【问题标题】:WCF Publish error: Metadata contains a reference that cannot be resolved:WCF 发布错误:元数据包含无法解析的引用:
【发布时间】:2013-07-24 09:24:28
【问题描述】:

我有一个 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>

【问题讨论】:

    标签: wcf web-services iis publish


    【解决方案1】:

    真的希望微软能够提供更好的诊断,以便在构建或运行时为我们提供有关 WCF 配置错误的更有针对性的信息 - 我不在乎哪个,但它浪费了很多多年来的开发时间是不真实的。

    </rant>
    

    对我来说,这个可笑的通用错误的原因是:

    <endpoint address="mexTcp" binding="mexTcpBinding" contract="IMetadataExchange"/>
    

    应该是这样的:

    <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
    

    为了在 IDE 中很容易突出显示的东西,尝试启用 Net.Tcp 花了两个小时。两个小时!!!

    【讨论】:

    • 我投了赞成票,因为你使用了fart-arsing这个短语。
    • 我也是,嘻嘻:-)
    • 只有两个小时?
    【解决方案2】:

    由于这是谷歌针对此错误显示的第一批帖子之一,我想参与我的解决方案:

    我在更改运行良好的系统中的代码时遇到了类似的错误,但在我的开发系统上更新引用失败。该参考位于 silverlight 项目中,并且与集成在周围网站中的 WCF 相关(我猜是标准配置)。

    我的错误信息包括

    "WCF 元数据包含无法解析的引用:'一些 有趣的路径'。内容类型 text/html; charset=utf-8 的响应 消息与绑定的内容类型不匹配 (应用程序/soap+xml;charset=utf-8)。”

    我的网站使用授权角色,这就是问题/解决方案的基础。为了更新服务参考,我必须允许所有用户:

    <?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>
    

    【讨论】:

      【解决方案3】:

      在这里查看答案MSDN forum

      当您定义网络 tcp 协议时,您需要确保您使用的是端点合约中定义的IMetadataExchange 合约。为此的服务行为也需要包含&lt;serviceMetadata /&gt; 标签。据我了解,如果您想在 VS 中托管和生成代理/发现,这几乎是您的配置的样板代码。

      <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
      

      【讨论】:

      • @sundog ... 从您最初糟糕的质量答案中,现在已将其编辑为合理的答案。 StackOverflow 社区不赞成仅链接的答案,因此您应该始终努力提供答案,并提供从链接页面获取的附加信息,如上所示。有关如何改进答案的更多信息,请参阅帮助中心的 How do I write a good answer? 页面。
      【解决方案4】:

      尝试从我们的一台测试服务器更新服务参考时,收到了基本相同的错误消息。确切的文本(删除的 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。添加了相应的hosts文件入口,代理成功生成。

      【讨论】:

        【解决方案5】:

        当我的一个 DataMember 对象有一个构造函数时,我遇到了这个问题。我不确定它是构造函数的参数还是它里面的东西。但是我能够通过使构造函数成为一个静态方法来解决这个问题,该方法返回一个它之前构造的新类型。

        【讨论】:

          【解决方案6】:

          我可以正常查看 wsdl,但无法通过“添加服务引用”菜单在 Visual Studio 2010 中添加服务

          尝试使用 WSDL 工具,打开 Visual Studio 命令提示符:

          wsdl.exe /out:c:\temp\WebService.cs /order www.webadress.com?wsdl
          

          【讨论】:

            【解决方案7】:

            添加到导致错误 415 的事物列表中,在我的情况下,我忘记将 [DataContract][DataMember] 属性添加到服务使用的类中。

            【讨论】:

              【解决方案8】:

              在我的情况下,服务返回的类之一缺少空构造函数。添加后错误被删除。

                  public ClassName() {}
              

              【讨论】:

                猜你喜欢
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                相关资源
                最近更新 更多