2011-01-10 3 views
4

WCF 서비스를 보유하고 있으며 MSTest 프로젝트에서이 서비스에 대한 참조를 만들었습니다. 여기에 내가 서비스 메소드를 호출하고 방법 예는 다음과 같습니다WCF : 자신의 WCF 서비스를 호출 할 수 없습니다.

나는 다음과 같은 오류가있어 대신 실행의
IEnrollmentService serviceClient = ChannelFactory<IEnrollmentService> 
    .CreateChannel(new BasicHttpBinding(), 
        new EndpointAddress("http://localhost/EnrollmentService.svc")); 

PublishResult res = serviceClient.PublishEnrollmentProfile(...); 

:

지금까지 내가 이해로, ContractFilter 및 EndpointDispatcher 사이에 약간의 문제가

The content type application/xml; charset=utf-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 710 bytes of the response were: ' Sendera:ActionNotSupported The message with Action '' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).'. ---> System.Net.WebException: The remote server returned an error: (500) Internal Server Error..

.

EnrollmentServiceClient serviceClient = new EnrollmentServiceClient("http://localhost/EnrollmentService.svc"); 

PublishResult res = serviceClient.PublishEnrollmentProfile(...); 

나에게 또 다른 오류 반환 :

Could not find endpoint element with name ' http://localhost/McActivation/EnrollmentService.svc ' and contract 'EnrollmentServiceReference.IEnrollmentService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this name could be found in the client element..

을 나는

나는 또한 다른 방법으로 WCF 서비스 메소드를 호출하려고했습니다 ... goodgle하려고했으나 이해 아무것도 발견했습니다

Question1 :

WCF 서비스 클라이언트를 인스턴스화하는 올바른 방법은 무엇입니까?

Questions2는 :

내 경우에 어떤 문제가 있습니까?

고마워요.

P. WcfTestClient를 사용하여 서비스에 연결할 수있는 몇 가지 문제가 있습니다. 자세한 내용은 여기를 참조하십시오. WCF service: Can't call methods through the 'WebHttpBinding' endpoint

P.P.

<system.serviceModel> 
<services> 
    <service name="McActivationApp.EnrollmentService" behaviorConfiguration="McActivationApp.EnrollmentServicBehavior"> 
    <endpoint address="" binding="webHttpBinding" contract="McActivationApp.IEnrollmentService"/> 
    <endpoint address="mex" binding="mexHttpBinding" contract="McActivationApp.IEnrollmentService" /> 
    </service> 
</services> 
<behaviors> 
    <serviceBehaviors> 
    <behavior name="McActivationApp.EnrollmentServicBehavior"> 
     <serviceMetadata httpGetEnabled="True"/> 
     <serviceDebug includeExceptionDetailInFaults="False" /> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> 
</system.serviceModel> 
+2

H 귀하의 서비스 구성을 모른 채 말할 수 있습니다. –

+0

wcf 테스트 클라이언트에 연결할 수 있습니까? http://msdn.microsoft.com/en-us/library/bb552364.aspx –

+0

이와 같은 상황에서 저는 작업 예제로 시작하여 작동하기 시작할 때까지 응용 프로그램을 리버스 엔지니어링합니다. MSDN에서 제공하는 샘플 앱은 다음과 같습니다. http://msdn.microsoft.com/en-us/library/dd936243.aspx –

답변

8

귀하의 문제는 이것이다 : - 그는 REST ("XML을 - 이상 - HTTP") 엔드 포인트입니다 ....

webHttpBinding 엔드 포인트를 정의하여 서비스 설정 다음은 서버 측 WCF 서비스의 구성입니다

귀하의 클라이언트는 basicHttpBinding을 사용하며 SOAP 바인딩입니다. 즉 과 호환됩니다.

서비스 측에서 제공하는 서비스 끝점이 클라이언트가 연결할 수 있도록하려면이 값을 변경해야합니다. 그래서

:

  • 중 하나가 basicHttpBinding과 서비스 설정에 다른 엔드 포인트를 추가하고 엔드 포인트

또는 연결 :

  • 변화 클라이언트 측 webHttpBinding
  • 를 사용하는
+0

나는 양쪽에서 basicHttpBinding을 수행했습니다 ... 감사합니다. 하지만 서버가 'webHttpBinding'을 사용하도록 구성되어 있고 클라이언트가 'webHttpBinding'을 사용하도록 전환 한 경우 EndpointDispatcher에서 ContractFilter가 일치하지 않아 수신기에서 처리 할 수없는 '메시지가 여전히 발생합니다'라는 오류 메시지가 표시됩니다. . – Budda

+0

또한 서비스를 인스턴스화하는 첫 번째 방법은 정확하지만 두 번째는 여전히 작동하지 않습니다. – Budda

+0

@Budda : 클라이언트를 webHttpBinding으로 전환하면 SOAP에서 REST로 변경되므로 클라이언트가 완전히 다시 생성됩니다. side proxy. 이 두 표준은 ** 완전히 다릅니다 ** 클라이언트 측 구성을 변경하면 충분하지 않습니다 ..... –