tags:

views:

37

answers:

0

I have a service being hosted in a web project. The service file *.svc is actually extending the service implementation, and then adding several ServiceHost instances as listeners for the main extending code base. In essence I'm selfhosting several of the services my base service is a client too.

rough code sample:

public class MyServiceClass : MyServiceClassImplentationCode, IDisposable 
{
    List<ServiceHost> hosts = null;
    Uri baseAddress = new Uri("net.tcp://localhost:5555/");



public MyServiceClass ()
    :base()
{

    NetTcpBinding tcpBinding = new NetTcpBinding();
    tcpBinding.PortSharingEnabled = true;
    hosts = new List<ServiceHost>();
    //create the service hosts

    ServiceHost sharedResourcesHost = new ServiceHost(typeof(MySharedResourcesService), baseAddress);
    hosts.Add(sharedResourcesHost);

//add several other service hosts

    //open hosts
    foreach (ServiceHost host in hosts)
    {
        host.Open();
    }

}

So the code above works fine, until I add IServiceBehavior to either the base class or this impelmenting class. When I do that it throws an error on the first host.Open() call.

Here is the error I get:

The ChannelDispatcher at 'net.tcp://localhost:5555/UserSharedResources' with contract(s) '\"IUserSharedResourceProvider\"' is unable to open its IChannelListener.

InnerException Message: A registration already exists for URI 'net.tcp://localhost:5555/UserSharedResources

Here is the client endpoint in question above:

endpoint name="MyLifeUserResources_TCP" address="net.tcp://localhost:5555" UserSharedResources" binding="netTcpBinding contract="MyLife.ServiceContracts.IUserSharedResourceProvider"

This only happens when I add the IServiceBehavior interface to the either the Base class or the *.svc code.

I have had no luck in googling an answer.