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>
Your problem is this: your service config defines a
webHttpBindingendpoints – that’s a REST (“Xml-over-HTTP”) endpoint….Yet, your client uses a
basicHttpBindingand 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:
basicHttpBindingand connect to that endpointor:
webHttpBinding