当我尝试多个终点时,我收到以下错误。
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端口共享服务。这是我可以检查的。
答案 0 :(得分: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的功能。
答案 1 :(得分:1)
可能是您使用相同的端口进行HTTP和TCP绑定。尝试将TCP绑定上的端口更改为8732或8731以外的任何其他内容。
答案 2 :(得分:1)
我建议您启用tracing以便更好地了解问题。在显示错误消息时,WCF可能是一个b * tch。
答案 3 :(得分:0)
这可能是tcp绑定/配置的问题,而不是多个绑定的问题。
要测试它,请删除对http绑定的引用,并查看tcp绑定是否可以单独工作。