WCF service fails to start when more than one service is available
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>
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
精彩评论