title: How can I add a XML prefix to fields in WCF Message Serialization?
body: <p>How can I add a XML prefix to fields in WCF Message Serialization?</p>
  
  <p>I'm connecting up to a Java Spring web service from .NET, and an object that I pass in with parameters is being serialized as you would expect:</p>
  
  <pre><code>&lt;MyClass&gt;
    &lt;field1&gt;Field 1 Value&lt;/field1&gt;
    &lt;field2&gt;Field 2 Value&lt;/field2&gt;
  &lt;/MyClass&gt;
  </code></pre>
  
  <p>However, the web service requires that the class and fields are prefixed with a namespace, let's say namespace <code>blah</code>, so what I want is:</p>
  
  <pre><code>&lt;blah:MyClass&gt;
    &lt;blah:field1&gt;Field 1 Value&lt;/blah:field1&gt;
    &lt;blah:field2&gt;Field 2 Value&lt;/blah:field2&gt;
  &lt;/blah:MyClass&gt;
  </code></pre>
  
  <p>How can I make this happen in WCF? Is there a way to adjust the XML serialization attributes on my class?</p>
  
  <p><strong>Edit:</strong> WSDL for this particular entity is as follows (edited to remove business-specific field names, but everything else is the same):</p>
  
  <pre><code>&lt;wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:sch0="http://www.domain.com/app/schemas/entityone" xmlns:sch1="http://www.domain.com/app/schemas/types" xmlns:sch2="http://www.domain.com/app/schemas/query" xmlns:sch3="http://www.domain.com/app/schemas/entitytwo" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.domain.com/app/schemas/entityone" targetNamespace="http://www.domain.com/app/schemas/entityone"&gt;
    &lt;wsdl:types&gt;
    &lt;schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:types="http://www.domain.com/app/schemas/types" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://www.domain.com/app/schemas/entityone" xmlns:tns="http://www.domain.com/app/schemas/entityone"&gt;
    &lt;import namespace="http://www.domain.com/app/schemas/types" /&gt; 
  
  &lt;element name="TheClassName"&gt;
   &lt;complexType&gt;
    &lt;sequence&gt;
     &lt;element name="field1" type="string" /&gt; 
     &lt;element name="field2" type="string" /&gt; 
     &lt;element name="field3" type="string" /&gt; 
     &lt;element name="field4" type="string" /&gt; 
     &lt;element name="field5" type="string" /&gt; 
     &lt;element name="field6" type="string" /&gt; 
     &lt;element name="field7" type="string" /&gt; 
     &lt;element name="field8" type="string" /&gt; 
    &lt;/sequence&gt;
   &lt;/complexType&gt;
  &lt;/element&gt;
  
  &lt;wsdl:binding name="NameOfBindingHere" type="tns:ReturnTypeHere"&gt;
    &lt;soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" /&gt; 
     &lt;wsdl:operation name="OperationNameHere"&gt;
       &lt;soap:operation soapAction="" /&gt; 
       &lt;wsdl:output name="ResponseTypeHere"&gt;
          &lt;soap:body use="literal" /&gt; 
       &lt;/wsdl:output&gt;
     &lt;/wsdl:operation&gt;
  &lt;/wsdl:binding&gt;
  </code></pre>