Configuring WCF DataContract namespace using the ContractNamespace attribute

When developing my service, I decided that I wanted to customize the namespaces resulting from WSDL.

For DataContracts, I came across a ContractNamespace attribute, which seemed like a good alternative to shortcuts, allowing you to uniquely set the same namespace for each 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 mastering, I was successful when I finally set the attribute's ClrNamespace property 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 didn't this work the first way? My assumption was that without specifying the CLR firmware name, this attribute will affect all data types in the collection.

+4
source share
1 answer

If I am not mistaken if the ClrNamespace parameter ClrNamespace omitted, then the contract namespace parameter is applied to objects in the global namespace.

+4
source

All Articles