title: How to customize WCF XML serialization
body: <p>We have an existing SOAP web service interface that we want to implement using WCF for a new application. This seems to work fine except for one small detail. The XML namespace of the return type of a function must be different than the XML namespace of the web service itself. And for the life of me, I can't get it to work.</p>
  
  <p>I've recreated the same problem with a small sample project.
  The WCF interface:</p>
  
  <pre><code>[XmlSerializerFormat]
  [ServiceContract(Namespace = "urn:outer-namespace")]
  public interface IService1
  {
      [OperationContract]
      MyClass DoStuff(int value);
  }
  
  [Serializable]
  public class MyClass
  {
      [XmlElement(ElementName = "DataString")]
      public string MyString { get; set; }
  }
  </code></pre>
  
  <p>The web service implementation:</p>
  
  <pre><code>    public class Service1 : IService1
  {
      public MyClass DoStuff(int value)
      {
          return new MyClass { MyString = "Wooh!" };
      }
  }
  </code></pre>
  
  <p>A response from this webservice is then serialized as:
  (Omitting SOAP stuff)</p>
  
  <pre><code>  &lt;DoStuffResponse xmlns="urn:outer-namespace"&gt;
       &lt;DoStuffResult&gt;
          &lt;DataString&gt;Wooh!&lt;/DataString&gt;
       &lt;/DoStuffResult&gt;
    &lt;/DoStuffResponse&gt;
  </code></pre>
  
  <p>But we want the &lt;DoStuffResult&gt; to be of xmlns="urn:inner-namespace".</p>
  
  <p>I've tried adding a [return: XmlElement(...)] on the interface function or the web service function, but that doesn't take. Also an [XmlType] or [XmlRoot] on the MyClass class definition doesn't work.</p>
  
  <p>Does anyone have an idea how to change the serialized XML namespace (or element name) of the object that is the return value of a WCF web service function?</p>