title: Escaping ampersands (&) on generated requests from a WCF class
body: <p>I'm having issues with strings containing ampersands in my client generated from dotnet-svcutil.</p>
  
  <p>When I recieve a response through the client all ampersands are serialized as </p>
  
  <pre><code>&lt;Users xsi:type=\"xsd:string\"&gt;John &amp;amp; Jane&lt;/Users&gt;
  </code></pre>
  
  <p>When i extract the value from the request in my code it has been deserialized as an ampersand</p>
  
  <pre><code>UserResponse users  = await GetUsersAsync()
  
  users.Names = "John &amp; Jane"
  </code></pre>
  
  <p>In a later stage i need to send the value of the users back like this</p>
  
  <pre><code>await SetUsersAsync(users.Names);
  </code></pre>
  
  <p>When i intercept the generated soap request I can see that the ampersand has not been escaped </p>
  
  <pre><code>public class MyMessageInspector : IClientMessageInspector
      {
          public void AfterReceiveReply(ref Message reply, object correlationState)
          {
              var xml = reply.ToString(); // This shows &lt;Users xsi:type=\"xsd:string\"&gt;John &amp;amp; Jane&lt;/Users&gt;
          }
  
          public object BeforeSendRequest(ref Message request, IClientChannel channel)
          {
              var xml = request.ToString(); // This shows &lt;Users xsi:type=\"xsd:string\"&gt;John &amp; Jane&lt;/Users&gt;
  
              return null;
          }
      }
  
  </code></pre>
  
  <p>This causes the whole request to fail in the connected service. From the information I've found online the ampersand should be converted to <code>&amp;amp;</code> by the serializer. I could convert the value myself, but since I'm only returning a value I got from the soap client, I would have to check and convert every single string that is returned back.</p>
  
  <p>Do you have any suggestions on how I could configure the generated client to automatically escape ampersands?</p>