title: WebService SOAP Encoding UTF-16 instead of UTF-8
body: <p>Is it possible to force a WebService in C# .NET to use encoding UTF-16 instead of UTF-8?</p>
  
  <p>I have created a simple WebService which receives a XML Document.</p>
  
  <p><strong>WebService.asmx</strong></p>
  
  <pre><code>public class WebApplication1 : WebService
  {
      [WebMethod(Description = "Test")]
      public string Test(XmlDocument xmlDocument)
      {
          return "Test";
      }
  }
  </code></pre>
  
  <p><strong>Output</strong></p>
  
  <pre><code>POST /WebService.asmx HTTP/1.1
  Host: localhost
  Content-Type: text/xml; charset=utf-8
  Content-Length: length
  SOAPAction: "http://tempuri.org/Test"
  
  &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;
    &lt;soap:Body&gt;
      &lt;Test xmlns="http://tempuri.org/"&gt;
        &lt;xmlDocument&gt;xml&lt;/xmlDocument&gt;
      &lt;/Test&gt;
    &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  </code></pre>
  
  <p>If I try an pass an XML Document that is UTF-16 encoded, I get the following error:</p>
  
  <pre><code>XML Content:
  &lt;?xml version="1.0" encoding="utf-16"?&gt; &lt;Affiliate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" leadinnumber="ABCDABCD" xmlns:xsd="http://www.w3.org/2001/XMLSchema" mediaid="30000"&gt;
    &lt;Details&gt;
      &lt;Amount&gt;5000&lt;/Amount&gt;
      &lt;FirstName&gt;Delivery&lt;/FirstName&gt;
      &lt;Surname&gt;Testing&lt;/Surname&gt;
      &lt;Tel&gt;02034056978&lt;/Tel&gt;
      &lt;Email&gt;adfsdfsdfsd@live.co.uk&lt;/Email&gt;
    &lt;/Details&gt;
  &lt;/Affiliate&gt;
  
  Post Response
  &lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
    &lt;soap:Body&gt;
      &lt;soap:Fault&gt;
        &lt;soap:Code&gt;
          &lt;soap:Value&gt;soap:Receiver&lt;/soap:Value&gt;
        &lt;/soap:Code&gt;
        &lt;soap:Reason&gt;
          &lt;soap:Text xml:lang="en"&gt;System.Web.Services.Protocols.SoapException: Server was unable to process request. ---&amp;gt; System.Xml.XmlException: There is no Unicode byte order mark. Cannot switch to Unicode. at System.Xml.XmlTextReaderImpl.Throw(Exception e) at System.Xml.XmlTextReaderImpl.ThrowWithoutLineInfo(String res) at System.Xml.XmlTextReaderImpl.CheckEncoding(String newEncodingName) at System.Xml.XmlTextReaderImpl.ParseXmlDeclaration(Boolean isTextDecl) at System.Xml.XmlTextReaderImpl.Read() at System.Web.Services.Protocols.SoapServerProtocol.SoapEnvelopeReader.Read() at System.Xml.XmlReader.MoveToContent() at System.Web.Services.Protocols.SoapServerProtocol.SoapEnvelopeReader.MoveToContent() at System.Web.Services.Protocols.SoapServerProtocolHelper.GetRequestElement() at System.Web.Services.Protocols.Soap12ServerProtocolHelper.RouteRequest() at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message) at System.Web.Services.Protocols.SoapServerProtocol.Initialize() at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean&amp;amp; abortProcessing) --- End of inner exception stack trace ---&lt;/soap:Text&gt;
        &lt;/soap:Reason&gt;
        &lt;soap:Detail /&gt;
      &lt;/soap:Fault&gt;
    &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  </code></pre>
  
  <p>Any help would be much appreciated :-)</p>