WCF Service Client: The content type text/html; charset=utf-8 of the response message does not match the content type of the binding

后端 未结 19 2248
情书的邮戳
情书的邮戳 2020-11-27 18:30

I\'ve got a WCF Service running on my local IIS server. I\'ve added it as a service reference to a C# Website Project and it adds fine and generates the proxy classes automa

相关标签:
19条回答
  • 2020-11-27 18:44

    I had a similar situation, but the client config was using a basicHttpBinding. The issue turned out to be that the service was using SOAP 1.2 and you can't specify SOAP 1.2 in a basicHttpBinding. I modified the client config to use a customBinding instead and everything worked. Here are the details of my customBinding for reference. The service I was trying to consume was over HTTPS using UserNameOverTransport.

    <customBinding>
        <binding name="myBindingNameHere" sendTimeout="00:03:00">
            <security authenticationMode="UserNameOverTransport" includeTimestamp="false">
                <secureConversationBootstrap />
            </security>
            <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
                  messageVersion="Soap12" writeEncoding="utf-8">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
            </textMessageEncoding>
            <httpsTransport manualAddressing="false" maxBufferPoolSize="4194304"
                  maxReceivedMessageSize="4194304" allowCookies="false" authenticationScheme="Basic"
                  bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                  keepAliveEnabled="true" maxBufferSize="4194304" proxyAuthenticationScheme="Anonymous"
                  realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
                  useDefaultWebProxy="true" requireClientCertificate="false" />
        </binding>
    </customBinding>
    
    0 讨论(0)
  • 2020-11-27 18:44

    Hy, In my case this error appeared because the Application pool of the webservice had the wrong 32/64 bit setting. So this error needed the following fix: you go to the IIS, select the site of the webservice , go to Advanced setting and get the application pool. Then go to Application pools, select it, go to "Advanced settings..." , select the "Enable 32 bit applications" and make it Enable or Disable, according to the 32/64 bit type of your webservice. If the setting is True, it means that it only allows 32 bit applications, so for 64 bit apps you have to make it "Disable" (default).

    0 讨论(0)
  • 2020-11-27 18:45

    NOTE: If your target server endpoint is using secure socket layer (SSL) certificate

    Change your .config setting from basicHttpBinding to basicHttpsBinding

    I am sure, It will resolve your problem.

    0 讨论(0)
  • 2020-11-27 18:48

    If your are using both wshttpbinding along with https request, then i resolved it by using the below configuration change.

     <security mode="TransportWithMessageCredential">
                        <transport clientCredentialType="None" />
                        <message clientCredentialType="Certificate" />
                    </security>
    
    0 讨论(0)
  • 2020-11-27 18:51

    Try browsing to http://localhost/ScraperService.svc in the web browser on the server hosting the service, using the same Windows credentials that the client normally runs under.

    I imagine that IIS is displaying an html error message of some description instead of returning xml as expected.

    This also can occur when you have an http proxy server that performs internet filtering. My experience with ContentKeeper is that it intercepts any http/https traffic and blocks it as "Unmanaged Content" - all we get back is an html error message. To avoid this, you can add proxy server exception rules to Internet Explorer so that the proxy doesn't intercept traffic to your site:

    Control Panel > Internet Options > Connections > LAN Settings > Advanced > Proxy Settings

    enter image description here

    0 讨论(0)
  • 2020-11-27 18:52

    what's going on is that you're trying to access the service using wsHttpBind, which use secured encrypted messages by default (secured Messages). On other hand the netTcpBind uses Secured encrypted channels. (Secured Transport)... BUT basicHttpBind, doesn't require any security at all, and can access anonymous

    SO. at the Server side, Add\Change this into your configuration.

    <bindings>
        <wsHttpBinding>
         <binding name="wsbind"> 
             <security mode="Message">
                 <transport clientCredentialType="Windows" proxyCredentialType="None" />
                 <message clientCredentialType="Windows" negotiateServiceCredential="true"
                                algorithmSuite="Default" establishSecurityContext="true" />
             </security>
         </binding>
        </wsHttpBinding>
    </bindings>
    

    then add change your endpoint to

    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="wsbind" name="wshttpbind" contract="WCFService.IService" > 
    

    That should do it.

    0 讨论(0)
提交回复
热议问题