WCF多个绑定

Jos*_*osh 8 c# wcf wcf-binding

当我尝试多个终点时,我收到以下错误..

System.ServiceModel.AddressAlreadyInUseException: The TransportManager failed to listen on the supplied URI using the NetTcpPortSharing service: the service failed to listen.
   at System.ServiceModel.Channels.SharedConnectionListener.SharedListenerProxy.Register()
   at System.ServiceModel.Channels.SharedConnectionListener.SharedListenerProxy.Open(Boolean isReconnecting)
   at System.ServiceModel.Channels.SharedConnectionListener.StartListen(Boolean isReconnecting)
   at System.ServiceModel.Channels.SharedConnectionListener..ctor(BaseUriWithWildcard baseAddress, Int32 queueId, Guid token, OnDuplicatedViaDelegate onDuplicatedViaCallback)
   at System.ServiceModel.Channels.SharedTcpTransportManager.OnOpenInternal(Int32 queueId, Guid token)
   at System.ServiceModel.Channels.SharedTcpTransportManager.OnOpen()
   at System.ServiceModel.Channels.TransportManager.Open(TransportChannelListener channelListener)
   at System.ServiceModel.Channels.TransportManagerContainer.Open(SelectTransportManagersCallback selectTransportManagerCallback)
   at System.ServiceModel.Channels.TransportChannelListener.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.ConnectionOrientedTransportChannelListener.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.TcpChannelListener`2.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.ReliableChannelListenerBase`1.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open()
   at Microsoft.Tools.SvcHost.ServiceHostHelper.OpenService(ServiceInfo info)
Run Code Online (Sandbox Code Playgroud)

这是我的App.Config内容

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <bindings>
      <netTcpBinding>
        <binding name="tcpBinding" transferMode="Buffered" portSharingEnabled="true">
          <reliableSession enabled="true" />
          <security mode="None">
            <transport clientCredentialType="None" protectionLevel="None" />
            <message clientCredentialType="None" />
          </security>
        </binding>
      </netTcpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="WcfServiceLibrary1.Service1Behavior"
        name="WcfServiceLibrary1.Service1">
        <endpoint address="" binding="wsHttpBinding" contract="WcfServiceLibrary1.IService1">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <endpoint address="Service" binding="netTcpBinding" bindingConfiguration="tcpBinding"
          name="testTcp" contract="WcfServiceLibrary1.IService1" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8731/Design_Time_Addresses/WcfServiceLibrary1/Service1/" />
            <add baseAddress="net.tcp://localhost:8731/Design_Time_Addresses/WcfServiceLibrary1/Service" />

          </baseAddresses>

        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="WcfServiceLibrary1.Service1Behavior">
          <!-- 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="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>
Run Code Online (Sandbox Code Playgroud)

如果有人可以指导我错在哪里,那将会很棒.

在App.Config和Windows Service中都启用了Net TCP端口共享服务.这是我可能检查的内容.

jri*_*sta 13

您无法在两个不同的绑定之间共享相同的端口,这些绑定基于您上面发布的配置,您当前正在执行此操作.您需要将wsHttp绑定放在与net.tcp绑定不同的端口上.net.tcp端口共享的目的是允许多个进程为多个net.tcp绑定使用相同的端口...不跨多个不同的绑定和协议共享单个端口.

要成功利用WCF net.tcp端口共享,您需要启动"Net.Tcp端口共享服务"(请注意,它在名称中明确声明了Net.Tcp).您可能还希望将其设置为自动启动,因此如果重新启动,则不必继续启动它.启动端口共享Windows服务后,您可以在同一进程中,在同一物理计算机上跨多个进程共享任何net.tcp绑定的单个端口.需要共享端口的每个net.tcp绑定都需要将portSharingEnabled属性设置为true.如果您执行上述操作,那么您应该能够在任何进程中为任何启用了端口共享的net.tcp端点重用相同的端口.

这将不允许您与任何wsHttp绑定,basicHttp绑定,任何MSMQ绑定或任何第三方绑定共享相同的端口.这是特定于WCF附带的netTcpBinding的功能.

供参考:http: //msdn.microsoft.com/en-us/library/ms734772.aspx

  • HTTP是一种通过TCP/IP传输进行操作的应用程序协议.WCF的Tcp.Net也是一种应用协议,尽管是专有协议,它通过TCP/IP传输进行操作.两者都使用tcp网络传输层,但是它们之间没有任何关系. (4认同)

And*_*ite 1

您可能对 HTTP 和 TCP 绑定使用相同的端口。尝试将 TCP 绑定上的端口更改为 8732 或 8731 以外的任何端口。