2012-08-26 4 views
1

여러 계약 (현재 2 건)을 구현할 WCF Rest Service를 개발 중입니다. 기본 웹 사이트에서 IIS에 솔루션을 배포했습니다.WCF 복수 계약 계약 서비스

서비스 '이면 MyService'구현 복수의 ServiceContract 형식없이 엔드 포인트는 구성 파일에 정의되어 있습니다 :

http://localhost/wcfrestsample/myservices/service1/customers: 

내가 잘못된 연산 예외 다음 얻을 : URI를 액세스하는. WebServiceHost는 서비스가 단일 ServiceContract 만 구현하는 경우에만 기본 끝점을 설정할 수 있습니다. 단일 ServiceContract 만 구현하도록 서비스를 변경하거나 구성 파일에서 명시 적으로 서비스의 끝점을 정의하십시오.

<system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="MyServiceBehavior"> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
      <serviceMetadata httpGetEnabled="true" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <services> 
     <service behaviorConfiguration="MyServiceBehavior" name="MyService"> 
     <endpoint address="service1" binding="webHttpBinding" contract="WcfRestServiceSample.IMyService1" /> 
     <endpoint address="service2" binding="webHttpBinding" contract="WcfRestServiceSample.IMyService2" /> 
     </service> 
    </services> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> 
    <standardEndpoints> 
     <webHttpEndpoint> 
     <!-- 
      Configure the WCF REST service base address via the global.asax.cs file and the default endpoint 
      via the attributes on the <standardEndpoint> element below 
     --> 
     <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/> 
     </webHttpEndpoint> 
    </standardEndpoints> 
    </system.serviceModel> 

    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"> 
     <add 
     name="UrlRoutingModule" 
     type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> 
    </modules> 
    </system.webServer> 

내가 뭔가를 놓치고 다음과 같이

namespace WcfRestServiceSample 
{ 
    //Data Items... 

    public class Customer 
    { 
     public String Address { get; set; } 
     public String Name { get; set; } 
    } 

    public class Employee 
    { 
     public String EmployeeNumber { get; set; } 
     public DateTime JoiningDate { get; set; } 
     public Double Salary { get; set; } 
    } 

    //Service Contracts... 

    [ServiceContract] 
    public interface IMyService1 
    { 
     [WebGet(UriTemplate = "customers")] 
     IEnumerable<Customer> GetCustomers(); 
    } 

    [ServiceContract] 
    public interface IMyService2 
    { 
     [WebGet(UriTemplate = "employees")] 
     IEnumerable<Employee> GetEmployees(); 
    } 

    //Service Implementation... 

    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)] 
    public class MyService : IMyService1, IMyService2 
    { 
     public IEnumerable<Customer> GetCustomers() 
     { 
      return new List<Customer> 
      { 
       new Customer{ Address = "customer 1 address", Name = "Customer 1" }, 
       new Customer{ Address = "customer 2 address", Name = "Customer 2" } 
      }; 
     } 

     public IEnumerable<Employee> GetEmployees() 
     { 
      return new List<Employee> 
      { 
       new Employee{ EmployeeNumber = "Employee 1", JoiningDate = new DateTime(1995, 5, 5), Salary = 5555.55 }, 
       new Employee{ EmployeeNumber = "Employee 2", JoiningDate = new DateTime(1998, 8, 8), Salary = 8888.88 } 
      }; 
     } 
    } 

    //The Global.asax 

    public class Global : HttpApplication 
    { 
     void Application_Start(object sender, EventArgs e) 
     { 
      RouteTable.Routes.Add(new ServiceRoute("MyServices", new WebServiceHostFactory(), typeof(MyService))); 
     } 
    } 
} 

설정 파일의 내용은 다음과 같습니다 아래

코드 세부 사항입니까?

+0

당신이 아직 해결책을 찾았나요? 나는 똑같은 문제를 겪고있다. –

답변

0

여러 계약으로 작업 할 때 기본 주소를 전혀 사용할 수 없습니다. 엔드 포인트의 상대 주소가 각 엔드 포인트에 대해 고유 URI를 작성하는 경우에도 마찬가지입니다. 그 바보 같아. 끝점에서 전체 주소를 언급 해보십시오. 나는 그것이 그 때 작동 할 것이라는 점을 생각한다.

즉 같은 엔드 포인트합니다

<endpoint address="http://localhost/wcfrestsample/myservices/service1" binding="webHttpBinding" contract="WcfRestServiceSample.IMyService1" /> 
<endpoint address="http://localhost/wcfrestsample/myservices/service2" binding="webHttpBinding" contract="WcfRestServiceSample.IMyService2" />