6

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

8 回答 8

11

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

</rant>

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

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

应该是这样的:

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

围绕尝试启用 Net.Tcp 进行了两个小时的放屁,以解决在 IDE 中很容易突出显示的内容。两个小时!!!

于 2016-10-13T20:29:35.287 回答
3

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

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

我的错误信息包括

“WCF 元数据包含无法解析的引用:'一些有趣的路径'。响应消息的内容类型 text/html;charset=utf-8 与绑定的内容类型不匹配(application/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>
于 2014-10-20T13:34:56.983 回答
2

Check the answer here MSDN forum

When you define a net tcp protocol you need to ensure you are using IMetadataExchange contract defined in an endpoint contract. The service behaviour for this also needs to contain the <serviceMetadata /> tag. From what i have understood, this is pretty much boilerplate code for your config if you are wanting to host and generate proxys / discover in VS.

<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
于 2013-07-24T10:14:52.433 回答
1

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

于 2015-01-02T18:15:37.477 回答
0

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

于 2017-07-03T18:52:28.840 回答
0

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

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

wsdl.exe /out:c:\temp\WebService.cs /order www.webadress.com?wsdl
于 2016-08-04T05:00:27.620 回答
0

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

于 2016-03-17T22:43:38.620 回答
0

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

    public ClassName() {}
于 2018-01-02T16:27:09.213 回答