2011-08-17 2 views
2

내 WCF 서비스를 설정하려면 WCF The Right Way ... The Manual Way의 메서드를 느슨하게 수행하고 있습니다.수동 코드 (구성 코드 또는 자동 코드 없음)를 사용하여 WCF 서비스 호출

// Setup a client so we can call our web services. 
public class EmployeeClient :IEmployeeService 
{ 
    private readonly IEmployeeService EmployeeChannel; 

    public EmployeeClient(Binding binding, string address) 
    { 
     var endpointAddress = new EndpointAddress(address); 

     EmployeeChannel = new ChannelFactory<IEmployeeService> 
           (binding, endpointAddress).CreateChannel(); 
    } 

    public EmployeeResponse SaveOrUpdateEmployee(EmployeeContract employee) 
    { 
     return EmployeeChannel.SaveOrUpdateEmployee(employee); 
    } 
} 

내가 이들 서비스 중 일부를 호출 할 :

I는 다음과 같습니다 수동으로 생성 된 프록시 클래스가 있습니다. 그러나 나는 (I 일부 통합 테스트를 설정하고 내가 필요한 것보다 더 종속성을하지 않습니다.) 어떤 설정 파일을 사용하지 않으 나는 현재 이런 식으로 그들에게 전화하려고

:

serviceHost = SelfServiceHost.StartupService(); 

employeeClient = new EmployeeClient(new BasicHttpBinding(), 
            SelfServiceHost.StartUpUrl); 

EmployeeResponse employeeResponse = employeeClient.SaveOrUpdateEmployee(emp); 

나는이 예외 얻고 있다고 할 때 :

System.ServiceModel.ProtocolException: Content Type text/xml; charset=utf-8 was not supported by service http://localhost:8090/EmployeeService . The client and service bindings may be mismatched. ---> System.Net.WebException: The remote server returned an error: (415) Cannot process the message because the content type 'text/xml; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8'..

을 내가 단지 코드 작업 내 서비스에 전화를하려면 어떻게해야합니까?

+0

을보고이 댓글의 게시로, 튜토리얼 링크는 질문에 게시 ... WCF 호스트가 wsHttpBinding를 가지고 있으며, 여러분의 클라이언트 측 BasicHttpBinding 또는 유사한 것으로 의심 튜토리얼을 더 이상로드하지 않습니다. 튜토리얼을 다른 곳에서 찾을 수 없었지만 샘플 프로젝트 코드로이 튜토리얼에 대한 빠른 참조를 찾을 수 있었다. http://www.codeproject.com/Articles/114139/WCF-The-Right-Way- A-Quick-Reference-Guide – Sean

답변