2011-09-06 4 views
1

WCF를 처음 사용하고 하나의 프로젝트에 여러 서비스가 있고 단일 종단점을 노출하는 방법을 알고 싶습니다. 나는 집에서 일을하고 인터페이스를 사용하여 이것을 달성 할 수 있음을 깨달았습니다. 그러나 나는 이것을 계속할 수 없다.단일 종단점을 노출하는 다중 서비스

모두 의견을 제공 할 수 있습니까?

예 :

  • 내가 클라이언트에서 Employee ServiceCustomer Service
  • 같은 서비스는 내가 IService.IEmployee.GetEmployee(); 또는 IService.ICustomer.GetCustomer()처럼 액세스해야합니다.

희망 나는 그것을 분명히했다. 제발 나를 안내해주십시오.

답변

0

서비스 (구현)가있는 경우 해당 서비스에 대해 끝점을 여러 개 노출 할 수 있습니다. 서비스 구현 클래스는 여러 서비스 계약을 구현할 수 있습니다.

public class YourServiceImplementation : IEmployeeService, ICustomerService 
{ 
    ..... 
} 

각 그러나 하나의 계약 그것과 연관 될 필요는이 서비스 구현을 위해 정의 엔드 포인트 - 당신이 동시에 여러 계약 지원하는 단일 엔드 포인트 가질 수 없습니다 :

<services> 
    <service name="YourNamespace.YourServiceImplementation"> 
     <endpoint name="Employee" 
      address="http://YourServer/Services/EmployeeServices.svc" 
      binding="basicHttpBinding" 
      contract="YourNamespace.IEmployeeService" /> 
     <endpoint name="Customer" 
      address="http://YourServer/Services/CustomerServices.svc" 
      binding="basicHttpBinding" 
      contract="YourNamespace.ICustomerService" /> 
    </service> 
</services> 

클라이언트가 직원과 고객 서비스에 모두 액세스해야하는 경우 각 서비스 계약에 하나씩 두 개의 클라이언트 측 프록시를 추가해야합니다.

+0

내가 할 수있는 이거 맘에 들어? <서비스 이름 = "YourNamespace.YourServiceImplementation"> <엔드 포인트 이름 = "SingleInterface" 주소 = "HTTP : //YourServer/Services/IServices.svc" 바인딩 = "은 BasicHttpBinding" 계약 = "YourNamespace.IService "/> CodeMaker

1

각 서비스는 항상 고유 한 종점을 가지며 서비스 내의 구현 된 각 서비스 계약에는 자체 종점이 필요합니다.

이 경우에는 외관이 필요합니다. Employee.Service와 Customer.Service의 로직을 래핑하는 단일 계약의 단일 서비스를 갖게됩니다.

가장 간단한 구현은 같은 것입니다 :

public interface ICustomerService { ... } 
public interface IEmployeeService { ... } 

[ServiceContract] 
public interface IService : ICustomerService, IEmployeeService { ... } 
// Your WCF service 
public class Service : IService { ... } 

지금 Service 모두 ICustomerService 또는 IEmployeeService 인터페이스를 구현 할 수 있습니다 또는 그냥 내부적으로 일부 구현의 인스턴스를 만들 수 있습니다 위임처럼 호출

public class Service : IService 
{ 
    private CustomerService customerService; 

    public Service() 
    { 
     customerService = new CustomerService(); 
    } 

    public Customer GetCustomer() 
    { 
     retunr customerService.GetCustomer(); 
    } 
} 
관련 문제