我有一个自托管 WCF 服务,它使用 net.tcp 协议(protocol)作为端点,它在带有普通 LAN 卡的 PC 上运行良好。
但是,我想支持具有双 LAN 卡的 PC,这给我带来了问题。我为两张卡分配了不同的 IP 地址(192.168.1.1 和 193.168.1.1)。然后,我更改了我的 app.config 文件以尝试通过使用第二个 IP 地址为 WCF 服务添加第二个终结点来支持双 LAN。 (我的 WCF 客户端可以选择使用两个端点地址中的哪一个。)
当我运行该服务时,我收到以下错误消息:
The ChannelDispatcher at 'net.tcp://193.168.1.1:59301/MyClientService' with contract(s) "'IMyClientService'" is unable to open its IChannelListener.
Additional information from inner exception: A registration already exists for URI 'net.tcp://193.168.1.1:59301/MyClientService'.
注意:如果我在 app.config 文件中更改第二个端点的端口号(例如,如果我使用 193.168.1.1:59302),服务将正常启动。这是一种解决方法,但如果可能的话,能够为两个 LAN 使用相同的端口会很有用。
哦,我在绑定(bind)上尝试了 portSharingEnabled(在运行 Net.TCP 端口共享服务的情况下),但这没有帮助。
提前致谢...
我的 app.config 文件如下所示:
<!-- Information about assembly binding and garbage collection -->
<runtime>
<generatePublisherEvidence enabled="false"/>
</runtime>
<system.serviceModel>
<services>
<service name ="MyNamespace.MyClientService" behaviorConfiguration="MyServiceBehavior">
<host>
<baseAddresses>
<!-- Using TCP -->
<add baseAddress = "net.tcp://localhost:59301/MyClientService/" />
</baseAddresses>
</host>
<!-- Using TCP -->
<endpoint
address="net.tcp://192.168.1.1:59301/MyClientService"
binding="netTcpBinding"
bindingConfiguration="NetTcpBinding_IMyClientService"
contract="MyNamespace.IMyClientService"
/>
<endpoint
address="net.tcp://193.168.1.1:59301/MyClientService"
binding="netTcpBinding"
bindingConfiguration="NetTcpBinding_IMyClientService"
contract="MyNamespace.IMyClientService"
/>
<!-- Metadata Endpoints -->
<!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
<!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
<endpoint
address="mex"
binding="mexTcpBinding"
contract="IMetadataExchange"
/>
</service>
</services>
<bindings>
<!-- ==================================================================================== -->
<!-- TCP/IP bindings -->
<netTcpBinding>
<binding name="NetTcpBinding_IMyClientService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" listenBacklog="10"
maxBufferPoolSize="524288" maxBufferSize="2147483647" maxConnections="10"
maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
<security mode="None">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
<message clientCredentialType="Windows" />
</security>
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior">
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<!-- <serviceMetadata httpGetEnabled="True"/> -->
<serviceMetadata/>
<!-- 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>
最佳答案
“localhost”解析为什么?
看起来您在“localhost”和两个附加端点上添加了一个基地址,其中一个端点可能会与 localhost 冲突。
尝试删除基地址,看看是否有所不同...
关于c# - 当尝试从 WCF 服务支持双 LAN 时,WCF 内部异常消息 "A registration already exists for URI ' net.tcp ://. .. .' ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3858642/