4

I have my WCF service, I've created reference to it from MSTest project. Here is example how I am calling service methods:

IEnrollmentService serviceClient = ChannelFactory<IEnrollmentService>
    .CreateChannel(new BasicHttpBinding(),
                   new EndpointAddress("http://localhost/EnrollmentService.svc"));

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

Instead of execution I've got the following error:

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:ActionNotSupportedThe 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..

As far as I understood, there are some issues between ContractFilter and EndpointDispatcher. I've tried to goodgle, but found nothing understandable...

I've also tried to call wcf service methods in another way:

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

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

That returns me another error:

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..

Question1:

What is a correct way to instantiate wcf service client?

Questions2:

What is wrong in my case?

Thanks a lot.

P.S. With some issues I can connect to service with WcfTestClient, more details are here: WCF service: Can't call methods through the 'WebHttpBinding' endpoint

P.P.S. Here is server side WCF service configuration:

<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>
Community
  • 1
  • 1
Budda
  • 18,015
  • 33
  • 124
  • 206

1 Answers1

8

Your problem is this: your service config defines a webHttpBinding endpoints - that's a REST ("Xml-over-HTTP") endpoint....

Yet, your client uses a basicHttpBinding and this is a SOAP binding - those are not compatible!

You need to change this to make sure the service endpoint(s) offered by the service side are such that the client can connect to it.

So:

  • either add another endpoint to your service config with the basicHttpBinding and connect to that endpoint

or:

  • change your client side to use webHttpBinding
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • I did that for basicHttpBinding on both sides... Thanks a lot! But if server is configured to use 'webHttpBinding' and I switch client to use 'webHttpBinding' I still receives 'The message with Action '' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher...' error message. – Budda Jan 10 '11 at 17:31
  • Also, the 1st way to instantiate service is a correct, the 2nd still doesn't work – Budda Jan 10 '11 at 17:31
  • @Budda: if you switch the client to webHttpBinding, you're also changing from SOAP to REST, and this means: completely recreate your client side proxy. Those two standards are **totally** different and just simply changing the client-side config won't be enough..... – marc_s Jan 10 '11 at 17:33
  • 1
    @Budda: the second way you're trying to create your client-side proxy expects to get the **name** of an endpoint config section in your config file (``) - not the URL as you're supplying... there's no constructor to take in just a service URL. – marc_s Jan 10 '11 at 17:34
  • Yes, 2nd way (when end point name is used as constructor parameter) also works... Earlier it showed that something is wrong with URI... Thanks a lot! – Budda Jan 10 '11 at 17:39