title: Setting WCF DataContract namespace using ContractNamespace attribute
body: <p>In designing my service, I decided that I wanted to customize the namespaces that appeared in the resulting WSDL.</p>
  
  <p>For the DataContracts, i came across the <a href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.contractnamespaceattribute.aspx" rel="nofollow noreferrer">ContractNamespace</a> attribute which seemed a nice shortcut alternative to setting the same namespace explicitly for every DataContract. My initial attempt looked like this:</p>
  
  <pre><code>[assembly:ContractNamespace("http://types.mycompany.com/2010/08/03")]
  namespace MyCompany.MyContracts
  {
      [DataContract]
      //...multiple datacontract classes here
  }
  </code></pre>
  
  <p>To my surprise, this did not work. After much tinkering, I was only successful when I finally set the <strong>ClrNamespace</strong> property of the attribute equal to my CLR namespace (MyCompany.MyContracts in the example). So something like this</p>
  
  <pre><code>[assembly:ContractNamespace("http://types.mycompany.com/2010/08/03",
            ClrNamespace="MyCompany.MyContracts")]
  </code></pre>
  
  <p>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. </p>