Changing the generated code namespace when adding a Service Reference

In my previous post I described how to change the default xml namespace used for serialization. But how can you change the generated namespace in your code? This is actually quite simple in Visual Studio. After adding the Service Reference, click on the Show All Files button in Solution explorer and look for the .svcmap file. In it you’ll find a <NamespaceMapping> section. Simply add the xml namespace and required Clr namespace to it:

    <NamespaceMappings>       <NamespaceMapping TargetNamespace="http://www.u2u.be/samples/wcf/2009"                         ClrNamespace="U2U.Samples"/>     </NamespaceMappings>