views:

420

answers:

1

I am running a WCF service from inside a exe (for debugging, it will be moved to the windows service when deployed) I got one service running fine inside of it however when I run a second service I get the exception

System.InvalidOperationException was unhandled
  Message=The ChannelDispatcher at 'http://backupsvr:8082/' with contract(s) '"IHttpGetHelpPageAndMetadataContract"' is unable to open its IChannelListener.
  Source=System.ServiceModel
  StackTrace:
       at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout)
       at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
       at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
       at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
       at System.ServiceModel.Channels.CommunicationObject.Open()
       at Service.Program.Main() in E:\Visual Studio 2010\Projects\Contract Flow Suite\Service\Program.cs:line 30
  InnerException: System.InvalidOperationException
       Message=A registration already exists for URI 'http://backupsvr:8082/'.
       Source=System.ServiceModel
       StackTrace:
            at System.ServiceModel.Channels.UriPrefixTable`1.RegisterUri(Uri uri, HostNameComparisonMode hostNameComparisonMode, TItem item)
            at System.ServiceModel.Channels.HttpTransportManager.Register(TransportChannelListener channelListener)
            at System.ServiceModel.Channels.TransportManager.Open(TransportChannelListener channelListener)
            at System.ServiceModel.Channels.TransportManagerContainer.Open(SelectTransportManagersCallback selectTransportManagerCallback)
            at System.ServiceModel.Channels.TransportChannelListener.OnOpen(TimeSpan timeout)
            at System.ServiceModel.Channels.HttpChannelListener.OnOpen(TimeSpan timeout)
            at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
            at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout)
       InnerException: 

here is the code that calls it.

using(ServiceHost hostRemoteUserManager = new ServiceHost(typeof(RemoteUserManager)))
using(ServiceHost hostDatabaseManagement = new ServiceHost(typeof(DatabaseManagement)))
try
{
    // Open the ServiceHost to start listening for messages.
    hostRemoteUserManager.Open();
    hostDatabaseManagement.Open(); //Exception on this line.
    // The service can now be accessed.
    Console.WriteLine("The service is ready.");
    Console.WriteLine("Press <ENTER> to terminate service.");
    Console.ReadLine();

    // Close the ServiceHost.
    hostRemoteUserManager.Close();
    hostDatabaseManagement.Close();
}

And here is my App.config file I used the Service Configuration Editor in visual studio 2010 to create it.

REMOVED

What do I need to change in my App.config file to allow more than one service other than running them on different ports. I would like to query http://backupsvr:8082/ and have it list all of the services available when I use the "Add Service Refrence" tool.

UPDATE --

I did Igor's suggestion it now runs on the same port however in the Add service refrence dialog I still need to type in http://backupsvr:8082/RemoteUserManager and http://backupsvr:8082/DatabaseManagement insted of just one http://backupsvr:8082/ . I do not know if what I am wanting is possable, it seems that is the way it should be by the way the dialog is designed. here is a update copy of my app.config file

<?xml version="1.0"?>
<configuration>
<system.diagnostics>
<sources>
  <source propagateActivity="true" name="System.ServiceModel" switchValue="Off,ActivityTracing">
    <listeners>
      <add type="System.Diagnostics.DefaultTraceListener" name="Default">
        <filter type="" />
      </add>
    </listeners>
  </source>
  <source name="System.ServiceModel.MessageLogging" switchValue="Warning, ActivityTracing">
    <listeners>
      <add type="System.Diagnostics.DefaultTraceListener" name="Default">
        <filter type="" />
      </add>
    </listeners>
  </source>
</sources>
</system.diagnostics>
<system.serviceModel>
<bindings>
  <mexHttpBinding>
    <binding name="MexBinding" />
  </mexHttpBinding>
</bindings>
<diagnostics>
  <messageLogging logMalformedMessages="false" logMessagesAtServiceLevel="false"
    logMessagesAtTransportLevel="false" />
</diagnostics>
<behaviors>
  <serviceBehaviors>
    <behavior name="RemoteUserManagerBehavior">
      <serviceMetadata httpGetEnabled="true" />
    </behavior>
    <behavior name="DatabaseManagementBehavior">
      <serviceMetadata httpGetEnabled="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<services>
  <service behaviorConfiguration="RemoteUserManagerBehavior" name="Service.RemoteUserManager">
    <endpoint address="" binding="netTcpBinding"
      bindingConfiguration="" name="RemoteUserManagerBinding" contract="Service.IRemoteUserManager" />
    <endpoint address="mex" binding="mexHttpBinding"
      bindingConfiguration="MexBinding" name="RemoteUserManagerMetadata"
      contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://backupsvr:8082/RemoteUserManager" />
        <add baseAddress="net.tcp://backupsvr:8081/RemoteUserManager" />
      </baseAddresses>
    </host>
  </service>
  <service behaviorConfiguration="DatabaseManagementBehavior" name="Service.DatabaseManagement">
    <endpoint address="" binding="netTcpBinding"
      bindingConfiguration="" name="DatabaseManagementBinding" contract="Service.IDatabaseManagement" />
    <endpoint address="mex" binding="mexHttpBinding"
      bindingConfiguration="MexBinding" name="DatabaseManagementMetaData"
      contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://backupsvr:8082/DatabaseManagement" />
        <add baseAddress="net.tcp://backupsvr:8081/DatabaseManagement" />
      </baseAddresses>
    </host>
  </service>
</services>
</system.serviceModel>
<startup><supportedRuntime version="v2.0.50727"/></startup></configuration>
+2  A: 

use for first service

<baseAddresses>
      <add baseAddress="net.tcp://backupsvr:8082/IRemoteUserManager"/>
    </baseAddresses>

use for second service

<baseAddresses>
      <add baseAddress="net.tcp://backupsvr:8082/IDatabaseManagement"/>
    </baseAddresses>

addresses should be unique

igor
You're right, though I understand Scotts question. Seems unnecessary with the 'address' part in the service config. I've also seen solutions with 2 different port numbers (8082, 8083)
Henk Holterman
It now runs with both on the same port. However I have to call http://backupsvr:8082/DatabaseManagement and http://backupsvr:8082/RemoteUserManager to get their interfaces. I would like it if i could just call the root and have them both show up. I will update the original posting with my changes.
Scott Chamberlain
I have never tried so, I want you to implement both interfaces by one class MySuperManagement. By using this way it could be done, I guess. :). Any way your web services' clients should understand what service use on that port/address (use different ports or different addresses).
igor