WCF:无法获取元数据错误

时间:2013-10-21 06:30:52

标签: c# wcf iis tcp

我的服务托管在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.

当我在wcf客户端中放入net.tcp地址时,我很惊讶为什么错误仅限于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>

2 个答案:

答案 0 :(得分:0)

由于它是netTcp绑定,因此无法将其添加到wcf测试客户端并对其进行测试。要在WCF测试客户端中使用,您还需要使用Http公开服务(即,同时使用Http和NetTcp绑定)。然后你可以浏览元数据并使用Http在wcf测试客户端中使用它。使用NetTcp绑定将服务公开给客户端。希望我已经回答了你的问题。

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

答案 1 :(得分:0)

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