Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force a net.tcp mex endpoint (mexTcpBinding) to participate in port sharing?

I have a WCF service which is hosted as a Windows Service. We would like to enable a mex endpoint at the same address (but with a '/mex' suffix). I have been trying to do this (unsuccessfully) using the following configuration:

<system.serviceModel>

  <services>
    <service
      name="MyCompany.MyService"
      behaviorConfiguration="defaultServiceBehavior">

      <host>
        <baseAddresses>
          <add baseAddress="net.tcp://localhost"/>
        </baseAddresses>
      </host>

      <endpoint
        address="MyService"
        binding="netTcpBinding"
        contract="MyCompany.IMyService"
        bindingConfiguration="netTcpBindingConfig"
        />

      <endpoint
        address="MyService/mex"
        binding="mexTcpBinding"
        contract="IMetadataExchange"
        />

    </service>
  </services>

  <behaviors>
    <serviceBehaviors>
      <behavior name="defaultServiceBehavior">
        <serviceMetadata />
      </behavior>
    </serviceBehaviors>
  </behaviors>

  <bindings>
    <netTcpBinding>
      <binding name="netTcpBindingConfig" portSharingEnabled="true" />
    </netTcpBinding>
  </bindings>

</system.serviceModel>

When it runs, the service host throws an AddressAlreadyInUseException complaining that "There is already a listener on IP endpoint 0.0.0.0:808". This actually makes sense to me because the port sharing service has opened that port in order to serve the MyService endpoint along with any other services requesting to share that port on this machine.

So it seems that the mex endpoint wants exlusive access to port 808. I can work around this by tweaking the mex endpoint like so:

<endpoint
  address="net.tcp://localhost:818/MyService/mex"
  binding="mexTcpBinding"
  contract="IMetadataExchange"
  />

This means that the mex endpoint now has its own exclusive port. The downside with this is that any other service which wants to expose a mex endpoint will also need a unique port for its mex endpoint. This makes it very unpredictable when looking for mex endpoints.

Is there a way to force the mex endpoint to participate in port sharing?

like image 917
Damian Powell Avatar asked Nov 12 '10 15:11

Damian Powell


People also ask

How do I enable TCP port sharing?

In the Name column of the list of services, right-click the Net. Tcp Port Sharing Service, and select Properties from the menu. To enable the manual start-up of the service, in the Properties window select the General tab, and in the Startup type box select Manual, and then click Apply.

Should NET TCP port sharing service be enabled?

As a security precaution, an administrator must manually enable the Net. TCP Port Sharing Service prior to first use. The Net. TCP Port Sharing Service exposes configuration options that allow you to manipulate several characteristics of the network sockets owned by the port sharing service.

What port does NET tcp use?

Port 808 is the Microsoft Net. TCP Port Sharing Service. "Windows Communication Foundation (WCF) provides a new TCP-based network protocol (net.

How do I install SMSvcHost EXE?

To configure the SMSvcHost.exe, create an XML configuration file named SmSvcHost.exe. config and place it in the same physical directory as the SMSvcHost.exe executable (for example, C:\Windows\Microsoft.NET\Framework\v4. 5).


1 Answers

Two options:

  1. The easy way: Change the entire binding for the mex point to netTcpBinding and have it reuse your bindingConfiguration. mexTCPBinding is only meant to be a convenience and is optional. If its not working for you, don’t use it.

  2. The hard way: You can modify the mexTCPBinding to enable sharing. The only example I’ve seen is in code here: Link

like image 148
ErnieL Avatar answered Sep 22 '22 21:09

ErnieL