WCF inner exception message “A registration already exists for URI 'net.tcp://…' ” when trying to support a dual LAN from a WCF service

喜你入骨 提交于 2019-12-11 09:15:53

问题


I have a self-hosted WCF service which is using the net.tcp protocol for an endpoint and it works fine on a PC with a normal LAN card.

However, I want to support PCs which have dual LAN cards and this gives me problems. I have assigned different IP addresses to the two cards (192.168.1.1 and 193.168.1.1). I then changed my app.config file to try to support the dual LAN by adding a second endpoint for the WCF service, using the second IP address. (My WCF client can handle selecting which of the two endpoint addresses to use.)

When I run the service, I get the following error message:

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'.

Note: If I change the port # on the second endpoint in the app.config file (e.g. if i use 193.168.1.1:59302), the service starts up fine. That's a workaround, but it would be useful to be able to use the same port for both LANs, if possible.

Oh, and I tried portSharingEnabled on the binding (with the Net.TCP Port Sharing Service running) but that didn't help.

Thanks in advance...

My app.config file looks like this:

<!-- 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>


回答1:


What does "localhost" resolve to?

Looks like you're adding a base address on "localhost" and two additional endpoints, one of which will probably conflict with localhost.

Try removing the base address, see if that makes a difference...




回答2:


It looks like the following section is duplicated:

  <endpoint 
                address="net.tcp://192.168.1.1:59301/MyClientService" 
                binding="netTcpBinding" 
                bindingConfiguration="NetTcpBinding_IMyClientService" 
                contract="MyNamespace.IMyClientService" 
        /> 

Just try removing one of then



来源:https://stackoverflow.com/questions/3858642/wcf-inner-exception-message-a-registration-already-exists-for-uri-net-tcp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!