我有一个WCF Web服务我试图发布到IIS。我可以查看wsdl,但无法通过“添加服务引用”菜单在Visual Studio 2010中添加服务。我收到以下错误:
Metadata contains a reference that cannot be resolved: 'http://localhost:4567/Service.svc?wsdl'.
The WSDL document contains links that could not be resolved.
There was an error downloading 'http://localhost:4567/Service.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://localhost:4567/Service.svc'.
Content Type application/soap+xml; charset=utf-8 was not supported by service http://localhost:4567/Service.svc. 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.
我在本地工作得很好,但如果发布到IIS则不行。
有谁知道造成这个问题的原因是什么?这是我的web.config,我是WCF的新手,所以可能错过了一些东西,谢谢:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<connectionStrings>
</connectionStrings>
</configuration>
答案 0 :(得分:7)
我真的希望Microsoft能够提供更好的诊断,以便在构建或运行时为我们提供有关WCF配置错误的更多有针对性的信息 - 我不关心哪些,但它浪费了很多多年来的发展时间是不真实的。
</rant>
对我来说,这个荒谬的一般性错误的原因是:
<endpoint address="mexTcp" binding="mexTcpBinding" contract="IMetadataExchange"/>
应该是这样的:
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
尝试启用Net.Tcp以便在IDE中轻松突出显示的内容,两个小时的放屁。两个小时!!!
答案 1 :(得分:3)
由于这是谷歌出现此错误的第一篇帖子之一,我想参加我的解决方案:
我在更改系统中的代码时遇到了类似的错误,但是在我的开发系统上更新引用失败了。该引用位于silverlight项目内,与周围网站中集成的WCF相关(我猜是标准配置)。
包含我的错误消息
&#34; WCF元数据包含无法解析的引用:&#39;一些 有趣的路径&#39;。内容类型text / html; charset = utf-8的回复 消息与绑定的内容类型不匹配 (application / soap + xml; charset = utf-8)。&#34;
我的网站使用授权角色,即问题/解决方案所在的角色。要更新服务引用,我必须允许所有用户:
<?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>
答案 2 :(得分:2)
在这里查看答案MSDN forum
定义net tcp协议时,需要确保使用端点合同中定义的
IMetadataExchange
合同。此服务行为还需要包含<serviceMetadata />
标记。根据我的理解,如果您想要在VS中托管和生成代理/发现,这几乎是您的配置的样板代码。
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
答案 3 :(得分:0)
尝试从我们的某个测试服务器更新服务引用时收到基本相同的错误消息。确切的文字(删除的IP等):
There was an error downloading 'http://xxx.xxx.xxx.xxx/xxxxxxxWSNew/Service.svc/_vti_bin/ListData.svc/$metadata'.
The request failed with HTTP status 400: Bad Request.
Metadata contains a reference that cannot be resolved: 'http://xxx.xxx.xxx.xxx/xxxxxxxWSNew/Service.svc'.
Content Type application/soap+xml; charset=utf-8 was not supported by service http://xxx.xxx.xxx.xxx/xxxxxxxWSNew/Service.svc. 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'..
这对我来说似乎不对,所以我使用Fiddler来查看VS尝试从元数据生成代理时从服务器返回的实际响应。结果是元数据指向VS服务器将自己标识为的主机名 - 例如wwww.server.com。添加了相应的主机文件条目,并成功生成了代理。
答案 4 :(得分:0)
当我的一个DataMember对象有一个构造函数时,我遇到了这个问题。我不确定它是构造函数的参数还是其中的内容。但是我能够通过使构造函数成为一个静态方法来解决它返回一个它以前构造的新类型。
答案 5 :(得分:0)
我可以查看wsdl,但无法通过“添加服务引用”菜单在Visual Studio 2010中添加服务
尝试使用WSDL工具,打开Visual Studio命令提示符:
http://census.daybreakgames.com/json/status?game=h1z1
答案 6 :(得分:0)
添加到导致错误415的事项列表中,在我的情况下,我忘了将[DataContract]
和[DataMember]
属性添加到服务使用的类中。
答案 7 :(得分:0)
在我的情况下,它是服务返回的一个类的缺少空构造函数。添加后,错误被删除。
Codable