Search code examples
wcfdatacontract

Is the WCF DataContract Namespace required


I have a WCF Client and A WCF Service,

There is a DataContract at each end. Namespace is required for me to deserialize the object on the client.

ie the blow doesn't work

[DataContract]
public class Framework
{
    [DataMember]
    public string Name { get; set; } 
}

but this does:

[DataContract(Namespace = "http//mysite.co.uk"]
public class Framework
{
    [DataMember]
    public string Name { get; set; } 
}

Why is this? I would have thought leaving the namespace would have meant that they both defaulted to http://tempuri.org and would both be fine.

It seems odd that namespace is required.

Does anyone have an explanation for this behaviour?


Solution

  • It should default to the tempuri namespace as you stated. I have done this many times, so I know that it works. My guess is that the incoming data is using the namespace http//mysite.co.uk, so that is causing it to fail. The namespace of the DataContract must match the namespace used in the SOAP message.

    Are you using assemblies or discovery to share your service contract? Maybe your contract is out of date on one end and needs to be refreshed (either by rerunning discovery or redeploying the shared assembly).