1

I am getting this error when consuming web service. I had tried many solutions given by experts but didn't worked in my project.

The content type application/xml;charset=utf-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8)

Error:

The content type text/html;charset=UTF-8 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.

My web.config file

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="ping_binding">
                    <security mode="Transport" />
                </binding>
                <binding name="ping_binding1" />
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="https://xxxx.com/ping/ping" binding="basicHttpBinding"
                bindingConfiguration="ping_binding" contract="NiprWebService.pingIF"
                name="ping" />
        </client>
    </system.serviceModel>
</configuration>

C# code

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

        using (var ws = new NiprWebService.pingIFClient())
        {
            using (new OperationContextScope(ws.InnerChannel))
            {
                var requestMessage = new HttpRequestMessageProperty();
                string authInfo = USER + ":" + PASS;

                authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
                requestMessage.Headers.Add("Authorization", "Basic " + authInfo);
                requestMessage.Headers.Add("Accept", "text/xml");
                requestMessage.Headers.Add("ContentType", "text/xml; charset=utf-8");
                //requestMessage.Headers.Add("Method", "POST");
                OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] =
                    requestMessage;
            }

            var gw = new NiprWebService.gateway();
            var pr = ws.gateway(gw);
            Console.WriteLine(pr.available);

        }
halfer
  • 19,824
  • 17
  • 99
  • 186
Imtiaz Ahmed
  • 11
  • 1
  • 3
  • Use fiddler to inspect the traffic. You will probanly see that your endpoint is not returning the content you expect. You probably have misspelled the url. What you get looks to be a html page which might well be returned by the hostinh webserver, not the webservice itself. – ZorgoZ Dec 18 '18 at 07:01
  • Please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](//meta.stackoverflow.com/q/326569) - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. – halfer Dec 18 '18 at 08:51

0 Answers0