8

尝试多个端点时出现以下错误..

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)

这是我的 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>

如果有人能指导我哪里错了,那就太好了。

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

4

4 回答 4

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

于 2009-08-19T23:49:53.083 回答
1

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

于 2009-08-19T05:01:43.297 回答
1

我建议您启用跟踪以更好地了解问题。WCF 在显示错误消息时可能会很糟糕。

于 2009-08-19T23:55:39.500 回答
0

这可能是 tcp 绑定/配置的问题,而不是多个绑定的问题。

要对其进行测试,请删除对 http 绑定的引用,并查看 tcp 绑定是否可以单独工作。

于 2009-08-19T07:18:09.603 回答