WCF Namespace Mismatch
A couple of days ago I have been bitten by an (really stupid, in hindsight) error when working with WCF services. I had a service and a client set up to use a contract using a contract link (see my post from a few months ago about using contract links as a replacement for service references).
For some reason, I couldn’t get any data transmitted from the client to the service. Everything worked great and there were no exceptions, the bindings seemed to be absolutely identical, the contract was the same contract and even the request message on the service side seemed to contain all the necessary information. Still, the data contract I was passing across the service boundaries was reaching the service end empty – an instance initialized with all the default parameters (albeit not a null reference).
So instead of this:
I was getting this:
After spending about 2 hours trying to debug and reproduce this issue, I went home and the next day on my day to work it hit me – the service assembly had an assembly-level [ContractNamespace] attribute indicating that the contracts should go to a non-default SOAP namespace! The client assembly didn’t have that [ContractNamespace] attribute (for some reason), so the namespace for the service contract and the data contract was entirely off; the client and the service were talking in different dialects of the same language…
Placing the [ContractNamespace] attribute in the client assembly fixed the problem immediately. As I said, it was a stupid thing to not notice, but fairly annoying nonetheless. Hopefully reading this post will help you avoid this kind of mistake in the future :-)
(The code required to reproduce this issue can be downloaded from my SkyDrive.)