WCF内容类型不匹配

时间:2012-08-15 11:15:12

标签: wcf iis

刚刚将一个WCF项目部署到IIS。

但是,当我尝试将服务引用添加到测试项目时,Visual Studio提供以下内容:

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.

所以我遇到了一个问题。服务的内容类型与客户期望的不匹配。

那么,我该如何解决呢?

2 个答案:

答案 0 :(得分:1)

检查客户端的App.Config或Web.Config,然后检查 ServiceModel 。最有可能的是 customBinding ,这与WCF服务发送的不同。

答案 1 :(得分:1)

由于这是google第一次发布此错误,我想参与我的解决方案:

我在更改系统中的代码时遇到了类似的错误,但是在我的开发系统上更新引用失败了。该引用位于silverlight项目内,与周围网站中集成的WCF相关(我猜是标准的配置)。我的错误消息包括“WCF元数据包含一个无法解析的引用:'一些有趣的路径'。内容类型text / html;响应消息的charset = utf-8与绑定的内容类型不匹配(application / soap) + xml; charset = utf-8)。“我的网站使用授权角色,即问题/解决方案所基于的角色。要更新服务引用,我必须允许所有用户:

<?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>