4

In designing my service, I decided that I wanted to customize the namespaces that appeared in the resulting WSDL.

For the DataContracts, i came across the ContractNamespace attribute which seemed a nice shortcut alternative to setting the same namespace explicitly for every DataContract. My initial attempt looked like this:

[assembly:ContractNamespace("http://types.mycompany.com/2010/08/03")]
namespace MyCompany.MyContracts
{
    [DataContract]
    //...multiple datacontract classes here
}

To my surprise, this did not work. After much tinkering, I was only successful when I finally set the ClrNamespace property of the attribute equal to my CLR namespace (MyCompany.MyContracts in the example). So something like this

[assembly:ContractNamespace("http://types.mycompany.com/2010/08/03",
          ClrNamespace="MyCompany.MyContracts")]

My question is: why did this not work the first way? My expectation was that by not specifying a CLR namepsace, this attribute would affect all datacontracts assembly-wide.

1 Answer 1

4

If I'm not mistaken, if the ClrNamespace is ommitted, then the contract namespace setting applies to objects in the global namespace.

Sign up to request clarification or add additional context in comments.

1 Comment

Yeah that clears it up. I was not even familiar with the global namepsace

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.