zoukankan      html  css  js  c++  java
  • WCF发布后远程访问的域名解析问题

    环境:

    VS2010 sp1,.net framework 4.0,windows server 2003 x64 ,iis 6.0

    症状:

    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绑定的,有说设置防火墙的,等等,试过都不行。

    很多网友都遇到此问题,非常郁闷,抱着大无畏的探索精神,最终找到两个解决方案:

    1、修改客户端hosts文件,路径C:WindowsSystem32driversetc,在hosts文件里添加一个映射:

    ip 域名

    例如:102.54.94.97     rhino.acme.com

    2、上面的办法,显然很山寨,我们不能要求使用服务的每一个客户端都去修改自己的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>
    复制代码
  • 相关阅读:
    angular11源码探索十四[表单校验器]
    2020年终总结
    vue使用腾讯地图获取当前位置
    腾讯地图+element-ui 实现地址搜索标记功能
    腾讯地图SDK公交路线规划Demo2
    腾讯地图SDK公交路线规划Demo
    腾讯位置服务地图SDK自定义路况和字体
    腾讯地图SDK自定义地图和路况
    3D地图的定时高亮和点击事件
    vue+腾讯地图 实现坐标拾取器功能
  • 原文地址:https://www.cnblogs.com/Alex80/p/5335359.html
Copyright © 2011-2022 走看看