I have a WCF service, I created a link to it from the MSTest project. Here is an example of how I call service methods:
IEnrollmentService serviceClient = ChannelFactory<IEnrollmentService> .CreateChannel(new BasicHttpBinding(), new EndpointAddress("http://localhost/EnrollmentService.svc")); PublishResult res = serviceClient.PublishEnrollmentProfile(...);
Instead of executing, I have the following error:
Content Type Application / xml; charset = utf-8 of the response message does not match the content type binding (text / xml; charset = utf-8). If using a custom encoder, make sure that the IsContentTypeSupported method is implemented properly. The first 710 bytes of the response were: '<Code> Sendera: ActionNotSupported Message with Action' 'could not be processed on the receiver, due to ContractFilter mismatch in EndpointDispatcher. This may be due to a contract mismatch (inappropriate actions between the sender and the recipient) or a communication / security mismatch between the sender and the recipient. Check that the sender and the recipient have the same agreement and the same obligation (including security requirements, for example. Communication, transport, Nobody). '. ---> System.Net.WebException: the remote server returned an error: (500) Internal server error.
As I understand it, there are some problems between ContractFilter and EndpointDispatcher. I tried for good, but did not find anything clear ...
I also tried calling the wcf service methods differently:
EnrollmentServiceClient serviceClient = new EnrollmentServiceClient("http://localhost/EnrollmentService.svc"); PublishResult res = serviceClient.PublishEnrollmentProfile(...);
This returns me another error:
An endpoint element could not be found with the name ' http: //localhost/McActivation/EnrollmentService.svc ' and the contract 'EnrollmentServiceReference.IEnrollmentService' in the client ServiceModel configuration. This may be because no configuration file was found for your application, or because there is no endpoint element matching this name can be found in the client element.
Question1:
What is the correct way to instantiate a wcf service client?
Questions2:
What is wrong in my case?
Thank you very much.
PS With some problems I can connect to the service using WcfTestClient, more details here: WCF service: it is impossible to call methods through the endpoint "WebHttpBinding"
PPS Here is the 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>