lundi 17 décembre 2018

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)

i am new here i need help urgently, 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);

        }




Aucun commentaire:

Enregistrer un commentaire