views:

112

answers:

2

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  A: 

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

Shiraz Bhaiji
Thanks for the comment. However, it is not duplicated exactly - one has 192... and one has 193... - and it's intentional in order to provide 2 endpoints, one for each LAN. The idea is that one endpoint services the first LAN and one services the second LAN (on the same PC).
Hugh Robinson
It may be the portnumber try changing 59301 for one of the endpoints
Shiraz Bhaiji
My original post says that if I use two different port numbers, it does indeed work, as you suggest. The reason I posed my question is that I would like to get it working using the same port number but two different IP addresses. Thanks
Hugh Robinson
A: 

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

Marc
That's an excellent suggestion - I'll try that. It should not be necessary since I am explicitly entering addresses for each endpoint. I'll try it and get back... :-)
Hugh Robinson
I tried removing localhost as you suggested - and I added full addresses to the MEX endpoints (using one of the IP addresses) - but I still get the same error. Thanks for the idea, though!
Hugh Robinson
OK, second try. Take a look at this article: http://msdn.microsoft.com/en-us/magazine/cc163412.aspxIf I'm reading it right, the default is to match all available addresses/hostnames for a given machine anyway. So you only need one endpoint and it will pick up on all configured addresses. Or configure the HostNameComparisonMode to be exact for specific address matching.
Marc
Thanks for the link - I'll trawl through that article and see what I come up with
Hugh Robinson