我正在从exe内部运行一个WCF服务(用于调试,它将在部署时移动到Windows服务)我在其中运行了一个服务正常但是当我运行第二个服务时我得到了异常
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:
这是调用它的代码。
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();
}
这是我的App.config文件,我使用visual studio 2010中的服务配置编辑器来创建它。
REMOVED
我需要在App.config文件中更改以允许多个服务,而不是在不同的端口上运行它们。我想查询http://backupsvr:8082/并列出我使用“添加服务参考”工具时可用的所有服务。
更新 -
我做了Igor的建议它现在在同一个端口上运行但是在Add service refrence对话框中我还需要输入http://backupsvr:8082/RemoteUserManager和http://backupsvr:8082/DatabaseManagement只有一个http://backupsvr:8082/。我不知道我想要的是否是可能的,似乎按照对话框的设计方式应该如此。这是我的app.config文件的更新副本
<?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>
答案 0 :(得分:7)
用于第一次服务
<baseAddresses>
<add baseAddress="net.tcp://backupsvr:8082/IRemoteUserManager"/>
</baseAddresses>
用于第二次服务
<baseAddresses>
<add baseAddress="net.tcp://backupsvr:8082/IDatabaseManagement"/>
</baseAddresses>
地址应该是唯一的