gpt4 book ai didi

c# - WCF 多重绑定(bind)

转载 作者:太空狗 更新时间:2023-10-29 18:17:21 26 4
gpt4 key购买 nike

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

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 端口共享服务。这是我所能检查的。

最佳答案

您不能在两个不同的绑定(bind)之间共享完全相同的端口,根据您在上面发布的配置,您目前正在这样做。您需要将 wsHttp 绑定(bind)在与 net.tcp 绑定(bind)不同的端口上。 net.tcp 端口共享的目的是允许多个进程将同一端口用于多个 net.tcp 绑定(bind)...而不是跨多个不同的绑定(bind)和协议(protocol)共享一个端口。

要成功利用 WCF net.tcp 端口共享,您需要启动“Net.Tcp 端口共享服务”(请注意,它在名称中明确说明了 Net.Tcp)。您可能还想将它设置为自动启动,这样您就不必在重新启动时继续启动它。一旦启动了端口共享windows服务,你就可以在同一个进程中,跨多个进程,在同一台物理机上为任何net.tcp绑定(bind)共享一个端口。每个需要共享端口的 net.tcp 绑定(bind)都需要将 portSharingEnabled 属性设置为 true。如果您执行上述操作,那么您应该能够在任何进程中为启用了端口共享的任何 net.tcp 端点重用相同的端口。

这将不允许您与任何 wsHttp 绑定(bind)、basicHttp 绑定(bind)、任何 MSMQ 绑定(bind)或任何第三方绑定(bind)共享同一端口。这是 WCF 自带的 netTcpBinding 特有的功能。

供引用: http://msdn.microsoft.com/en-us/library/ms734772.aspx

关于c# - WCF 多重绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1297865/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com