简体   繁体   中英

WCF content type mismatch

Have just deployed a WCF project to IIS.

However when I try to add the service reference to a test project, Visual Studio gives the following:

The document was understood, but it could not be processed.
  - The WSDL document contains links that could not be resolved.
  - There was an error downloading 'http://server1.local/WCFServices/serv1/serv1.svc?xsd=xsd0'.
  - The underlying connection was closed: An unexpected error occurred on a receive.
  - Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
  - An existing connection was forcibly closed by the remote host
    Metadata contains a reference that cannot be resolved: 'http://server1.local/WCFServices/serv1/serv1.svc?wsdl'.
    Content Type application/soap+xml; charset=utf-8 was not supported by service http://server1.local/WCFServices/serv1/serv1.svc?wsdl.  The client and service bindings may be mismatched.
The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'..
If the service is defined in the current solution, try building the solution and adding the service reference again.

So there's a problem, which I sorta get. The content type of the service is mismatched from what the client is expecting.

So, how do I fix it?

Check the App.Config or Web.Config of your client and check the ServiceModel . Most probably there is a customBinding which is different from what the WCF service is sending.

As this is the first post google shows up for this error, I want to participate with my solution:

I got a similar error while changing code in a system that was working well, but updating the reference on my development system failed. The reference is located inside a silverlight project and is related to a WCF integrated in the surrounding website (standard confiduration I guess). My error message included "WCF Metadata contains a reference that cannot be resolved: 'Some funny path'. The content type text/html; charset=utf-8 of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8)." My website uses authorization roles, thats where the problem/solution was based. For updating the service reference I had to allow all users:

<?xml version="1.0"?>
<configuration>
    <system.web>
        <!--<authorization>
            <allow users="*"/>            
        </authorization>-->
        <authorization>
            <deny users="?"/>
            <allow roles="role-1,role-2"/>
            <deny users="*"/>
        </authorization>
    </system.web>
</configuration>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM