DCSIMG
WCF Namespace Mismatch - All Your Base Are Belong To Us

All Your Base Are Belong To Us

Mostly .NET internals and other kinds of gory details

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: image

I was getting this: image

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

Comments

Posts about Language and Dialects as of April 6, 2009 | Tatuaj.org said:

Pingback from  Posts about Language and Dialects as of April 6, 2009 | Tatuaj.org

# April 6, 2009 5:20 PM

Jah said:

I downloaded your code to reporduce the issue.

Can you provide the code that fixed the problem?

# May 18, 2009 3:12 PM

jah said:

Where is the code that fixed the problem?

# May 18, 2009 7:04 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: