已经有一个wcf部署在IIS上,浏览器访问:http://www.xxxdemo.com/GetData.svc 已创建服务。若要测试此服务,需要创建一个客户端,并将其用于调用该服务。可以使用下列语法,从命令行中使用 svcutil.exe 工具来进行此操作:
svcutil.exe http://xxxdemo/GetData.svc?wsdl这将生成一个配置文件和一个包含客户端类的代码文件。请将这两个文件添加到客户端应用程序,并使用生成的客户端类来调用服务。例如:
...
点击“http://xxxdemo/GetData.svc?wsdl”会出现“网络无法访问或DNS解析错误”,如果手动在浏览器中输入“http://www.xxxdemo.com/GetData.svc?wsdl”就可以正常访问。添加服务引用的时候,会出现如下错误信息:URI http://www.xxxdemo.com/GetData.svc 处的文档未被识别为已知的文档类型。
来自各已知类型的错误信息可能有助于修复该问题:
- 来自“XML 架构”的报告是“无法识别此文档格式(内容类型为“text/html; charset=UTF-8”)。”。
- 来自“http://www.xxxdemo.com/GetData.svc”的报告是“无法识别此文档格式(内容类型为“text/html; charset=UTF-8”)。”。
- 来自“DISCO 文档”的报告是“下载“http://xxxdemo/GetData.svc?disco”时出错。”。
  - 未能解析此远程名称: 'xxxdemo'
- 来自“WSDL 文档”的报告是“无法识别此文档格式(内容类型为“text/html; charset=UTF-8”)。”。
元数据包含无法解析的引用:“http://www.xxxdemo.com/GetData.svc”。
元数据包含无法解析的引用:“http://www.xxxdemo.com/GetData.svc”。
如果该服务已在当前解决方案中定义,请尝试生成该解决方案,然后再次添加服务引用。
请问这可能是什么原因导致的,要怎么修改。

解决方案 »

  1.   

    补充说明下:
    不明白的地方:明明的是http://www.xxxdemo.com/GetData.svc, 
    为什么会变成http://xxxdemo/GetData.svc?disco而不是http://www.xxxdemo.com/GetData.svc?disco
      

  2.   

    通过域名访问么? 想实现 http://xxxdemo/GetData.svc?wsdl 就在你的 
    C:\Windows\System32\drivers\etc\hosts 文件里添加一行, 
    就把域名劫持为你定义的ip了
    如:
    192.168.1.100 server第2个问题是不是你配置的问题?这是我们的配置,对比下:
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <system.web>
        <compilation debug="true" targetFramework="4.0" />
      </system.web>
      <system.serviceModel>
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <!-- 为避免泄漏元数据信息,请在部署前将以下值设置为 false 并删除上面的元数据终结点 -->
              <serviceMetadata httpGetEnabled="true" />
              <!-- 要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息 -->
              <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true">
          <serviceActivations>
              <add relativeAddress="PersonService.svc" service="PersonsBLL.Persons" />
          </serviceActivations>
        </serviceHostingEnvironment>
      </system.serviceModel>
      <system.webServer>
        <modules runAllManagedModulesForAllRequests="true" />
      </system.webServer>
    </configuration>
      

  3.   

    楼上,先谢谢,第一个问题那样的确可以。那是不是表示每一台访问http://xxxdemo/GetData.svc?wsdl都要进行追加?第二个问题,不太懂,配置如下:
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
    <system.web>
              <customErrors mode="Off" />
    </system.web>
     <system.serviceModel>
      <behaviors>
       <serviceBehaviors>
        <behavior name="GetDataBehavior">
         <serviceMetadata httpGetEnabled="true" />
         <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
       </serviceBehaviors>
      </behaviors>
       <services>
         <service behaviorConfiguration="GetDataBehavior" name="GetData">
           <endpoint contract="IGetData" binding="wsHttpBinding" address="">
             <identity>
               <dns value="localhost"/>
             </identity>
           </endpoint>
         </service>
       </services>
     </system.serviceModel>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true" />
      </system.webServer>
    </configuration>另外:如果加上
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true">
          <serviceActivations>
              <add relativeAddress="PersonService.svc" service="PersonsBLL.Persons" />
          </serviceActivations>
        </serviceHostingEnvironment>
    的话,访问
    http://www.xxxdemo.com/GetData.svc?wsdl 就会出现无法识别的属性“multipleSiteBindingsEnabled"的错误。