Pages

Tuesday, September 11, 2012

Contract Mismatch error in WCF



Error Message:- "The message with Action 'Function1' 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)."




There are several causes

Cause 1: As the error message describes the contracts  in the client and the service have a mismatch. That means there is some difference between the proxy and the code in  services. There can be many reasons like we might have changed the attribute of one of the message contracts or datacontract etc but after that we forgot to generate the proxy using the svcutil.exe.  I have seen people do this a lot of times. We do generate a proxy when we add a new method or a datacontract but when we change an attribute like isWrapped = "True" we tend to forget to generate the proxy once again and add it to the client side. other reasons include we forget to check in the proxy file with the new changes or if we had a several branches of the code we might have not done the code synchronization properly. What ever may be the cause the only issue is that the contract between the client and the services  are not matching.

Solution 1:

The best solution to the problem is to regenerate the proxy using svcutil and then add the proxy to the client. In major case this solves the problem. This has solved the problem in all the cases I have seen this error.

Once the proxy is generated you can just cross verify the proxy if all the functions and required changes are present in the proxy. This will solve the problem. No need of wasting time on debug or testing.



Cause 2: In the config file the entry for the endpoint have different binding or contract.

E.g. :- In the services we might have used a wsHttpbinding but in Client we might have specified BasicHttpbinding. or say the contract names have a mismatch it may be a spelling mistake or the some or one of the letter is in upper case and in services its in lower case.


 Solution 2:

Check in the config file if the entries are proper if it is proper then try checking if the services are running properly by clicking on the services link that is .svc file after running it in the browser. if the service is not running properly then it might have happened that if the source control the dlls are referred from some other location than the folder we have actually mapped to.So check for the references is it proper if any references have been missed out .please add it else correct the mapping.


These 2 are the major causes and the solutions which are described here should solve the problem in majority of the cases.