2011-01-25 96 views
2

我在配置WCF服务时遇到了一些困难。我的要求是它公开了一个basicHttpBinding端点以及一个netTcpBinding端点。我的一些客户端是.NET 2.0,需要能够通过WSDL.exe生成代理。WCF基本的HTTP和NetTCP绑定,通过Mex暴露

它似乎工作的大部分 - 但是当我试图获得WSDL,它不合作。在浏览器中,它给了我一些SOAP XML标签,但绝对不是完整的WSDL。 WSDL.exe给了我一系列的错误:

错误:处理'http://1.2.3.4:9877/MyService/basicHttp?wsdl'时出错。

  • 该文件被理解,但它无法处理。
  • WSDL文档包含无法解析的链接。
  • 下载'http:// localhost:9877/MyService/basicHttp?wsdl = wsdl0'时出错。
  • 底层连接已关闭:无法连接到远程服务器。

这是我的主机配置。这里有什么东西会跳出来吗?

<system.serviceModel> 
    <services> 
    <service behaviorConfiguration="MyServiceBehavior" name="MyRunner"> 
     <endpoint address="netTcp" binding="netTcpBinding" bindingConfiguration="" contract="IMyRunner"> 
     <identity> 
      <dns value="localhost" /> 
     </identity> 
     </endpoint> 
     <endpoint address="basicHttp" binding="basicHttpBinding" bindingConfiguration="" contract="IMyRunner"> 
     </endpoint> 
     <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="" contract="IMetadataExchange" /> 
     <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" contract="IMetadataExchange" /> 
     <host> 
     <baseAddresses> 
      <add baseAddress="net.tcp://localhost:9876/MyService/netTcp" /> 
      <add baseAddress="http://localhost:9877/MyService/basicHttp" /> 
     </baseAddresses> 
     </host> 
    </service> 
    </services> 
    <behaviors> 
    <serviceBehaviors> 
     <behavior name="MyServiceBehavior"> 
     <serviceMetadata httpGetEnabled="true" /> 
     <serviceDebug includeExceptionDetailInFaults="false" /> 
     </behavior> 
    </serviceBehaviors> 
    </behaviors> 
</system.serviceModel> 
+0

请问您的请求是否需要.svc,例如'http://1.2.3.4:9876/MyService/basicHttp.svc?wsdl' – 2011-01-25 02:06:15

+0

@Chris O:我不这么认为 - 服务本身工作正常罚款没有。如果这有所作为,我将托管在Windows服务中,而不是IIS。 – 2011-01-25 03:11:19

回答

0

感谢提示家伙。原来问题出在baseAddress值指向“localhost”。在生成的WSDL中,它仍然会显示“localhost”,因此WSDL.exe显然试图访问本地主机(我的开发机器)而不是服务器。我将“localhost”更改为托管该服务的服务器的实际IP,并且WSDL.exe即使在.NET 1.1中也能成功运行。而且我仍然可以通过使用svcutil.exe来获得4.0版本。

1

如果你有两个MEX端点,每个需要一个单独地址 - 称之为一个 “MEX”,然后拨打对方 “mex2” 或东西:

<service behaviorConfiguration="MyServiceBehavior" name="MyRunner"> 
     <endpoint address="netTcp" binding="netTcpBinding" bindingConfiguration="" contract="IMyRunner"> 
     <identity> 
      <dns value="localhost" /> 
     </identity> 
     </endpoint> 
     <endpoint address="basicHttp" binding="basicHttpBinding" bindingConfiguration="" contract="IMyRunner"> 
     </endpoint> 
     <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="" contract="IMetadataExchange" /> 
     <endpoint address="mex2" binding="mexTcpBinding" bindingConfiguration="" contract="IMetadataExchange" /> 
     <host> 
     <baseAddresses> 
      <add baseAddress="net.tcp://localhost:9876/MyService/netTcp" /> 
      <add baseAddress="http://localhost:9877/MyService/basicHttp" /> 
     </baseAddresses> 
     </host> 
    </service> 

(OK所以要根据OP的意见,他不在IIS托管,所以这是不相关的)

另外:你在IIS托管?在这种情况下,你的基址(至少是HTTP的)是没有意义的 - SVC文件的服务器,虚拟目录和位置将决定你的服务地址:

http://YourServer/YourVirtualDirectory/SubDirectory/YourService.svc/basicHttp 

为你的“正常” SERVIC端点或

http://YourServer/YourVirtualDirectory/SubDirectory/YourService.svc/mex 

用于基于HTTP的MEX端点。