WCF发布后远程访问的域名解析问题

来源:互联网 发布:网络教育入学考试科目 编辑:程序博客网 时间:2024/06/06 09:30

环境:

VS2010 sp1,.net framework 4.0,windows server 2008 x64 ,iis 7.0

症状:

WCF开发测试,本地调用都正常。发布后,在浏览器中访问http://ip/yourService.svc,可以正常浏览,但svcutil.exe 显示的是域名:http://域名/YOurService.svc。

在VS中,添加服务引用,地址输入http://ip/YourService.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'.。如果该服务已在当前解决方案中定义,请尝试生成该解决方案,然后再次添加服务引用。

解决方案如下:

然后修改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>

重新发布,问题解决。

详情请参考:点击打开链接(http://www.cnblogs.com/deerbox/archive/2013/05/13/3076248.html)

0 0