【问题标题】:WCF:Cannot obtain metadata errorWCF:无法获取元数据错误
【发布时间】:2013-10-21 06:30:52
【问题描述】:

我的服务托管在 IIS7 上,启用了 net.tcp 协议。当我从 IIS 浏览服务时,我可以看到服务页面及其 tcp 地址,但如果我将该地址用于 WCF 测试客户端或任何应用程序作为服务参考 我在 wcf 客户端中收到此错误

Error: Cannot obtain Metadata from http://localhost:808/MyService/MyService.svc?wsdl 
If this is a Windows (R) Communication Foundation service to which you have access, 
please check that you have enabled metadata publishing at the specified address. 
For help enabling metadata publishing, 
 please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455
WS-Metadata Exchange Error 
URI: http://localhost:808//MyService/MyService.svc?wsdl
 Metadata contains a reference that cannot be resolved:
 'http:/localhost:808/MyService/MyService.svc?wsdl .
 There was no endpoint listening at
'http:/localhost:808/MyService/MyService.svc?wsdl that could accept the message. 
 This is often caused by an incorrect address or SOAP action. See InnerException, 
 if present, for more details.    
The remote server returned an error: (404) Not Found.HTTP GET Error 
URI: http:/localhost:808/MyService/MyService.svc?wsdl    
The HTML document does not contain Web service discovery information.

当我将 net.tcp 地址放入 wcf 客户端时,我很惊讶为什么错误只是关于 http

我的服务配置是

<?xml version="1.0" encoding="UTF-8"?>
<configuration>


 <system.web>
<compilation debug="true" targetFramework="4.0"/>
<httpRuntime maxRequestLength="102400" />
 </system.web>

 <system.serviceModel>
  <bindings>
    <netTcpBinding>
    <binding name="TcpBinding" maxBufferPoolSize="2147483647"
     maxBufferSize="2147483647" 
             closeTimeout="10:00:00" sendTimeout="10:00:00" openTimeout="10:00:00" 
         receiveTimeout="10:00:00"
      maxReceivedMessageSize="2147483647" portSharingEnabled="true" >
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <security mode="None"/>
      <reliableSession enabled="true" inactivityTimeout="10:00:00" />
    </binding>
    </netTcpBinding>
   </bindings>
   <services>
    <service behaviorConfiguration="MyService.MyServiceBehaviour" 
      name="MyService.MyService">
    <endpoint address="" binding="netTcpBinding" bindingConfiguration="TcpBinding"
      name="EndPointTCP" contract="MyService.IMyService" isSystemEndpoint="false" />
    <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
     </service>
   </services>
     <behaviors>
    <serviceBehaviors>
    <behavior name="MyService.MyServiceBehaviour">
      <serviceMetadata httpGetEnabled="false"  />
      <serviceDebug includeExceptionDetailInFaults="false" />
      <dataContractSerializer maxItemsInObjectGraph="2147483647" />
    </behavior>
    </serviceBehaviors>
   </behaviors>
    </system.serviceModel>

   <system.webServer>
     <modules runAllManagedModulesForAllRequests="true" />
      <directoryBrowse enabled="true" showFlags="Date, Time, Size, Extension, LongDate"       
       />
     </system.webServer>

  </configuration>

【问题讨论】:

  • 如果您尝试添加服务引用,那么 httpGetEnabled 应该在您的服务行为中为真
  • @SanjayRabadiya 好吧,我认为 tcp 绑定不需要它。因为我不希望通过 http 协议访问我的服务。
  • 所以我假设服务使用 http 绑定。
  • 为 'EndPointTCP' 端点指定完整地址,如 'net.tcp://localhost:8889/MyService'..
  • 我找到了根本原因,因为从 Windows 功能激活 WCF 非 http 激活存在一些问题,它总是给出错误,如操作无法完成。我能够在其他机器上运行我的服务但仍想知道 WCF 非 http 激活错误的可能原因。

标签: c# wcf iis tcp


【解决方案1】:

由于是netTcp Binding,所以不能在wcf测试客户端中添加并测试。要在 WCF 测试客户端中使用,您还需要使用 Http 公开服务(即同时使用 Http 和 NetTcp 绑定)。然后您可以浏览元数据并使用 Http 在 wcf 测试客户端中使用它。使用 NetTcp 绑定向客户端公开服务。希望我已经回答了你的问题。

注意:在您托管的网站下的 IIS 中,转到高级设置并将允许的绑定提及为“Http,NetTcp”。

【讨论】:

  • :"既然是netTcp Binding,就不能在wcf测试客户端中添加并测试吗?"..有可能,我成功​​了,我还在IIS中设置了启用的协议http 和 net.tcp 我找到了根本原因,因为从 Windows 功能激活 WCF 非 http 激活存在一些问题,它总是给出错误,例如无法完成操作。我可以在其他机器上运行我的服务,但仍然想要了解 WCF 非 http 激活错误的可能原因是什么
  • 您使用的 .Net 框架版本和操作系统是什么?因为微软有一个已知的错误,请检查此处的链接link
【解决方案2】:

我找到了根本原因,因为从 Windows 功能激活 WCF 非 http 激活时出现了一些问题,它总是给出诸如操作无法完成之类的错误。我可以在其他机器上运行我的服务,但仍然想知道WCF非http激活错误的可能原因是什么。

【讨论】:

    猜你喜欢
    • 2012-04-28
    • 2023-03-25
    • 2011-08-28
    • 2011-04-01
    • 2012-11-26
    • 2012-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多