环境:html
VS2010 sp1,.net framework 4.0,windows server 2003 x64 ,iis 6.0ios
症状:windows
WCF开发测试,本地调用都正常。发布后,在浏览器中访问http://ip/Service.svc,能够正常浏览,但svcutil.exe 显示的是域名:http://域名/Service.svc。浏览器
在VS中,添加服务引用,地址输入http://ip/Service.svc,点击前往,提示错误,内容以下:服务器
URI http://ip/Service.svc 处的文档未被识别为已知的文档类型。 来自各已知类型的错误信息可能有助于修复该问题: - 来自“XML 架构”的报告是“没法识别此文档格式(内容类型为“text/html; charset=UTF-8”)。”。 - 来自“http://ip/Service.svc”的报告是“没法识别此文档格式(内容类型为“text/html; charset=UTF-8”)。”。 - 来自“DISCO 文档”的报告是“下载“http://域名/Service.svc?disco”时出错。”。 - 未能解析此远程名称: '域名' - 来自“WSDL 文档”的报告是“没法识别此文档格式(内容类型为“text/html; charset=UTF-8”)。”。 元数据包含没法解析的引用:“http://域名/Service.svc”。 服务 http://ip/Service.svc 不支持内容类型 application/soap+xml; charset=utf-8。客户端和服务绑定可能不匹配。 远程服务器返回错误: (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'.。 若是该服务已在当前解决方案中定义,请尝试生成该解决方案,而后再次添加服务引用。
解决方案:
网上看了不少帖子,有说ip绑定的,有说设置防火墙的,等等,试过都不行。架构
不少网友都遇到此问题,很是郁闷,抱着大无畏的探索精神,最终找到两个解决方案:app
一、修改客户端hosts文件,路径C:\Windows\System32\drivers\etc,在hosts文件里添加一个映射:编辑器
ip 域名测试
例如:102.54.94.97 rhino.acme.comthis
二、上面的办法,显然很山寨,咱们不能要求使用服务的每个客户端都去修改本身的hosts文件。最终仍是须要在服务端解决。
解决方案参考:http://support.microsoft.com/kb/971842
When you use a Windows Communication Foundation (WCF) service in load-balanced scenarios in the Microsoft .NET Framework 3.0 in Windows Server 2003, Windows XP, Windows Vista and Windows Server 2008, you experience one or more of the following issues:
.....
In this scenario, when you try to generate a proxy from the metadata, the process fails because the metadata contains URIs that reference internal Web site instances.
步骤:
首先下载补丁包:http://archive.msdn.microsoft.com/KB971842/Release/ProjectReleases.aspx?ReleaseId=3228
安装后会提示重启,忽略之。
而后修改wcf的配置文件,添加红色部分部门,或者经过wcf配置文件编辑器,添加useRequestHeadersForMetadataAddress配置
<behaviors> <serviceBehaviors> <behavior name=""> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="true" /> <useRequestHeadersForMetadataAddress> <defaultPorts> <add scheme="http" port="8002" /> <add scheme="https" port="8002" /> </defaultPorts> </useRequestHeadersForMetadataAddress> </behavior> </serviceBehaviors> </behaviors>
从新发布,问题解决。