有2个端点的问题:wsHttpBinding和netTCPBinding

时间:2011-07-26 16:39:26

标签: c# .net wcf wcf-binding

我正在学习WCF并首先使用wsHttpBinding开发服务并将其托管在IIS7(win7)上,并从Windows客户端应用程序中使用该服务。它工作正常(使用WCF服务DLL方法)

我尝试了两个端点并添加了netTCpBinding。我遇到了错误

  

{TransportManager无法使用提供的URI侦听提供的URI   NetTcpPortSharing服务:因为它没有启动服务   禁用。

我已经启动了所需的服务,甚至重启了我的机器。在“服务”中,2个服务显示为自己启动..我已经在IIS中启用了所需的tcpnetbinding设置,如许多博客和msdn所知。

我的客户端应用配置是:

 <configuration>    
    <system.serviceModel>
        <bindings />
        <client>
           <endpoint name="httpEndpoint"
               address="http://MachineName:8000/FLOW5WCFService.svc"
               binding="wsHttpBinding"
               contract="FLOW5ServiceDLL.IFLOW5WCFService"/>
           <endpoint name="tcpEndpoint"
               address="net.tcp://MachineName:8082/FLOW5WCFService.svc"
               binding="netTcpBinding"
               contract="FLOW5ServiceDLL.IFLOW5WCFService"/>
        </client>
    </system.serviceModel>
</configuration>

服务web.config

<configuration>
   <system.serviceModel>
      <bindings>
         <netTcpBinding>
              <binding name="tcpBinding" 
                  portSharingEnabled="true"
                  closeTimeout="00:10:00" openTimeout="00:10:00"
                  receiveTimeout="00:10:00" sendTimeout="00:10:00" transactionFlow="true"
                  hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288"
                  maxReceivedMessageSize="2147483647">
                  <readerQuotas maxDepth="32" maxStringContentLength="2147483647"
                      maxArrayLength="2147483647" maxBytesPerRead="4096" 
                      maxNameTableCharCount="320000" />
              </binding>
         </netTcpBinding>
      </bindings>
      <services>
          <service behaviorConfiguration="FLOW5ServiceDLL.FLOW5WCFServiceBehaviour" 
                   name="FLOW5ServiceDLL.FLOW5WCFService">
             <endpoint 
                 address="" 
                 binding="wsHttpBinding" 
                 contract="FLOW5ServiceDLL.IFLOW5WCFService">
                 <identity>
                     <dns value="localhost" />
                 </identity>
             </endpoint>
             <endpoint
                 binding="netTcpBinding"
                 bindingConfiguration="tcpBinding"
                 contract="FLOW5ServiceDLL.IFLOW5WCFService"/>
            <endpoint 
                address="mex" 
                binding="mexHttpBinding" 
                contract="IMetadataExchange" />
            <host>
                <baseAddresses>
                     <add baseAddress="http://localhost:8000/" />
                     <add baseAddress="net.tcp://localhost:8082" />
                </baseAddresses>
            </host>
        </service>
   </services>
   <behaviors>
       <serviceBehaviors>
            <behavior name="FLOW5ServiceDLL.FLOW5WCFServiceBehaviour">
               <serviceMetadata httpGetEnabled="false" />
               <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
       </serviceBehaviors>
   </behaviors>
</system.serviceModel>
<system.web>
    <compilation debug="false" />
</system.web>
</configuration>

我在客户端代码

中创建了如下通道
ChannelFactory<IFLOW5WCFService> protocolFactory 
      = new ChannelFactory<IFLOW5WCFService>("tcpEndpoint");
l_oFLOW5Service = protocolFactory.CreateChannel();

有人可以告诉我,以防我的配置错误或者我需要做的其他任何设置吗?如果需要更多信息,请告诉我

提前致谢

1 个答案:

答案 0 :(得分:1)

我看到两件事:

1)在服务器的web.config中,您的netTcp端点没有地址。如果你想让netTcp端点监听net.Tcp的默认基地址,我仍然总是将address=""放入我的端点:

<endpoint
    address=""
    binding="netTcpBinding"
    bindingConfiguration="tcpBinding"
    contract="FLOW5ServiceDLL.IFLOW5WCFService"/>

2)在您的客户端中,您没有定义任何netTcpBinding配置,而在服务器端,您可以这样做。我现在没有看到任何关键设置 - 但为了安全起见,我建议您尝试在客户端的配置中使用相同的netTcpBinding配置,并在客户端的tcpEndpoint中使用它看看是否有任何区别。

如果什么都不起作用:为什么不尝试禁用/关闭服务器端的NetTcp端口共享?我在这里的示例中并没有真正看到任何需要 - 只要你没有真正需要它,只要尝试与它相处。