title: WCF Exception: Text Message Encoding and ISO-8859-1 Encoding
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1908030/calling-a-webservice-that-uses-iso-8859-1-encoding-from-wcf">Calling a webservice that uses ISO-8859-1 encoding from WCF</a>  </p>
  </blockquote>
  
  
  
  <p>I am trying to consume an external Web Service (the web service has PHP implementation) using VS 2008, .net 3.5, WCF( Environment : Windows XP and VS 2008). I add Service Reference to Web Service, VS generates WCF Proxy.</p>
  
  <p>Binding is basicHttpBinding.</p>
  
  <p>I call to method in Web Service, using Proxy, then I started getting a ProtocolException,  I received the following error message :</p>
  
  <blockquote>
    <p>System.ServiceModel.ProtocolException:
    The content type text/xml;
    charset=ISO-8859-1 of the response
    message does not match the content
    type of the binding (text/xml;
    charset=utf-8). If using a custom
    encoder, be sure that the
    IsContentTypeSupported method is
    implemented properly.</p>
    
    <p>The first 644 bytes of the response were: </p>
    
    <p>This was successful</p>
  </blockquote>
  
  <p>Well, I needed to call a service in iso-8859-1 encoding. </p>
  
  <p>Any useful sample source code for solve it?</p>
  
  <p><strong>Update:</strong></p>
  
  <p>The default encoder used in WCF only works with UTF-8 and UTF-16 (big and little endian).</p>
  
  <p>If I use textEncoding="iso-8859-1" in binding in app.config,</p>
  
  <p>I get this error:</p>
  
  <blockquote>
    <p>System.ArgumentException: No se admite
    la codificación de texto 'iso-8859-1'
    usada en el formato de mensaje de
    texto. Nombre del parámetro: encoding.</p>
    
    <p>System.ServiceModel.Channels.TextEncoderDefaults.ValidateEncoding(Encoding
    encoding)
    System.ServiceModel.Channels.TextMessageEncodingBindingElement.set_WriteEncoding(Encoding
    value)
    System.ServiceModel.BasicHttpBinding.set_TextEncoding(Encoding
    value)
    System.ServiceModel.Configuration.BasicHttpBindingElement.OnApplyConfiguration(Binding
    binding)
    System.ServiceModel.Configuration.StandardBindingElement.ApplyConfiguration(Binding
    binding)
    System.ServiceModel.Description.ConfigLoader.LookupBinding(String
    bindingSectionName, String
    configurationName, ContextInformation
    context)
    System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint
    serviceEndpoint, String
    configurationName)
    System.ServiceModel.ChannelFactory.ApplyConfiguration(String
    configurationName)
    System.ServiceModel.ChannelFactory.InitializeEndpoint(String
    configurationName, EndpointAddress
    address) ctor(String
    endpointConfigurationName,
    EndpointAddress remoteAddress)
    CreateSimplexFactory()
    CreateChannelFactory()
    CreateChannelFactoryRef(EndpointTrait`1
    endpointTrait)
    InitializeChannelFactoryRef() ctor()
    IntegracionEasyVista.ServiceEasyVista.WebServicePortTypeClient..ctor()
    in</p>
  </blockquote>
  
  <p>Update:</p>
  
  <p>Calling a web service that uses ISO-8859-1 encoding from WCF</p>
  
  <p><a href="https://stackoverflow.com/questions/1908030/calling-a-webservice-that-uses-iso-8859-1-encoding-from-wcf">Calling a webservice that uses ISO-8859-1 encoding from WCF</a></p>
  
  <p>This MSDN page (<a href="http://msdn.microsoft.com/en-us/library/ms751486(v=VS.90).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms751486(v=VS.90).aspx</a>) shows how to create a "CustomTextEncoder" which can support more than utf-8, utf-16 and unicode encodings. It includes full sample source code and was very useful for me to get things going.</p>
  
  <p>I use CustomTextMessageEncodingElement, but I get error: </p>
  
  <blockquote>
    <p>The content type text/xml; charset=ISO-8859-1 of the response message does not match the content type of the binding (text/xml;charset=iso-8859-1). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were:**</p>
  </blockquote>
  
  <p>From code of Samples MSDN, I modify the constructor from CustomTextMessageEncoder class:</p>
  
  <pre><code>public CustomTextMessageEncoder(CustomTextMessageEncoderFactory factory)
  {
      writerSettings = new XmlWriterSettings();
      writerSettings.Encoding = Encoding.GetEncoding(factory.CharSet);
      contentType = string.Format("{0};charset={1}", 
      factory.MediaType, this.writerSettings.Encoding.HeaderName);
  }
  </code></pre>
  
  <p>I replace "{0};charset={1}" by "{0}; charset={1}" (I have included an blank)</p>
  
  <p>Then, I get the error:</p>
  
  <blockquote>
    <p>The message version of the outgoing message (Soap11 (<a href="http://schemas.xmlsoap.org/soap/envelope/" rel="nofollow noreferrer">http://schemas.xmlsoap.org/soap/envelope/</a>) AddressingNone <br/>(<a href="http://schemas.microsoft.com/ws/2005/05/addressing/none" rel="nofollow noreferrer">http://schemas.microsoft.com/ws/2005/05/addressing/none</a>)) does not match that of the encoder <br/><br/>(Soap12 (<a href="http://www.w3.org/2003/05/soap-envelope" rel="nofollow noreferrer">http://www.w3.org/2003/05/soap-envelope</a>) Addressing10 (<a href="http://www.w3.org/2005/08/addressing" rel="nofollow noreferrer">http://www.w3.org/2005/08/addressing</a>)).<br/> Make sure the binding is configured with the same version as the message.</p>
  </blockquote>