uri 的注册已存在
A registration already exists for uri
我正在使用通用 WCF 主机扫描插件文件夹并加载实现类型 "IWebService"
的所有程序集
然后我使用 Ninject 开始托管 wcf 服务。
所有配置都在App.config.
当只有一个插件要加载时,这非常有效。
但是当我第二次尝试 start() 时,它抛出一个异常 "A registration already exists for URI"
我在 App.config 中定义了 2 个完全不同的服务,所以我真的很困惑。
这是App.config
<services>
<service name="GenericWebService.WebService" behaviorConfiguration="defaultBehavior">
<host>
<baseAddresses>
<!-- note, choose an available port-->
<add baseAddress="http://localhost:8092/GenericWebService/service" />
</baseAddresses>
</host>
<endpoint address="http://localhost:8092/GenericWebService/service" name="service1"
binding="basicHttpBinding" bindingConfiguration="soapBinding" contract="GenericWebService.ICalculator"/>
</service>
<service name="GenericWebService.WebService2" behaviorConfiguration="defaultBehavior">
<host>
<baseAddresses>
<!-- note, choose an available port-->
<add baseAddress="http://localhost:8093/GenericWebService2/service"/>
</baseAddresses>
</host>
<endpoint address="http://localhost:8093/GenericWebService2/service" name="service2"
binding="basicHttpBinding" bindingConfiguration="soapBinding" contract="GenericWebService.ICalculator2" />
</service>
</services>
这是我加载它们并启动主机的方式
private static void StartNinjectSelfHostFromPlugin(IEnumerable<IWebService> webServices )
{
foreach (var webService in webServices)
{
var ninjectType = (new NinjectServiceSelfHostFactory()).GetType();
var wcfConfiguration = typeof (NinjectWcfConfiguration)
.GetMethod("Create", Type.EmptyTypes)
.GetGenericMethodDefinition()
.MakeGenericMethod(new[]
{webService.GetType(),ninjectType })
.Invoke(null, new object[]{});
var x = new NinjectSelfHostBootstrapper(CreateKernel, wcfConfiguration);
_selfHostBootstrappers.Add(x);
x.Start();
}
}
如有任何建议,我们将不胜感激。
更新异常
System.InvalidOperationException: The ChannelDispatcher at 'http://localhost:809
2/GenericWebService/service' with contract(s) '"ICalculator"' is unable to open
its IChannelListener. ---> System.InvalidOperationException: A registration alre
ady exists for URI 'http://localhost:8092/GenericWebService/service'.
at System.ServiceModel.Channels.UriPrefixTable`1.RegisterUri(Uri uri, HostNama
eComparisonMode hostNameComparisonMode, TItem item)
at System.ServiceModel.Channels.HttpTransportManager.Register(TransportChanne
lListener channelListener)
at System.ServiceModel.Channels.TransportManager.Open(TransportChannelListene
r channelListener)
at System.ServiceModel.Channels.TransportManagerContainer.Open(SelectTranspor
tManagersCallback selectTransportManagerCallback)
at System.ServiceModel.Channels.TransportChannelListener.OnOpen(TimeSpan time
out)
at System.ServiceModel.Channels.HttpChannelListener`1.OnOpen(TimeSpan timeout
)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout)
--- End of inner exception stack trace ---
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 Ninject.Extensions.Wcf.SelfHost.NinjectWcfSelfHost.Start()
at Ninject.Web.Common.SelfHost.NinjectSelfHostBootstrapper.Start()
at TestApp.Program.StartNinjectSelfHostFromPlugin(IEnumerable`1 psoWebService
s) in c:\Users\william.davis\Documents\Visual Studio 2013\Projects\Service\TestA
pp\Program.cs:line 80
经过大量重构后,我可以正常工作,但我不知道它是否正常 'correct.' 为了让它正常工作,我基本上必须在我的网络服务中创建一个新的 IKernel class并且还让它继承自 NinjectModule 并在其中配置绑定。为什么我需要多个内核才能实现这一点?我应该补充一点,如果我不需要 Ninject 这可以通过使用标准 ServiceHost
我正在使用通用 WCF 主机扫描插件文件夹并加载实现类型 "IWebService"
的所有程序集然后我使用 Ninject 开始托管 wcf 服务。 所有配置都在App.config.
当只有一个插件要加载时,这非常有效。
但是当我第二次尝试 start() 时,它抛出一个异常 "A registration already exists for URI"
我在 App.config 中定义了 2 个完全不同的服务,所以我真的很困惑。
这是App.config
<services>
<service name="GenericWebService.WebService" behaviorConfiguration="defaultBehavior">
<host>
<baseAddresses>
<!-- note, choose an available port-->
<add baseAddress="http://localhost:8092/GenericWebService/service" />
</baseAddresses>
</host>
<endpoint address="http://localhost:8092/GenericWebService/service" name="service1"
binding="basicHttpBinding" bindingConfiguration="soapBinding" contract="GenericWebService.ICalculator"/>
</service>
<service name="GenericWebService.WebService2" behaviorConfiguration="defaultBehavior">
<host>
<baseAddresses>
<!-- note, choose an available port-->
<add baseAddress="http://localhost:8093/GenericWebService2/service"/>
</baseAddresses>
</host>
<endpoint address="http://localhost:8093/GenericWebService2/service" name="service2"
binding="basicHttpBinding" bindingConfiguration="soapBinding" contract="GenericWebService.ICalculator2" />
</service>
</services>
这是我加载它们并启动主机的方式
private static void StartNinjectSelfHostFromPlugin(IEnumerable<IWebService> webServices )
{
foreach (var webService in webServices)
{
var ninjectType = (new NinjectServiceSelfHostFactory()).GetType();
var wcfConfiguration = typeof (NinjectWcfConfiguration)
.GetMethod("Create", Type.EmptyTypes)
.GetGenericMethodDefinition()
.MakeGenericMethod(new[]
{webService.GetType(),ninjectType })
.Invoke(null, new object[]{});
var x = new NinjectSelfHostBootstrapper(CreateKernel, wcfConfiguration);
_selfHostBootstrappers.Add(x);
x.Start();
}
}
如有任何建议,我们将不胜感激。
更新异常
System.InvalidOperationException: The ChannelDispatcher at 'http://localhost:809
2/GenericWebService/service' with contract(s) '"ICalculator"' is unable to open
its IChannelListener. ---> System.InvalidOperationException: A registration alre
ady exists for URI 'http://localhost:8092/GenericWebService/service'.
at System.ServiceModel.Channels.UriPrefixTable`1.RegisterUri(Uri uri, HostNama
eComparisonMode hostNameComparisonMode, TItem item)
at System.ServiceModel.Channels.HttpTransportManager.Register(TransportChanne
lListener channelListener)
at System.ServiceModel.Channels.TransportManager.Open(TransportChannelListene
r channelListener)
at System.ServiceModel.Channels.TransportManagerContainer.Open(SelectTranspor
tManagersCallback selectTransportManagerCallback)
at System.ServiceModel.Channels.TransportChannelListener.OnOpen(TimeSpan time
out)
at System.ServiceModel.Channels.HttpChannelListener`1.OnOpen(TimeSpan timeout
)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout)
--- End of inner exception stack trace ---
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 Ninject.Extensions.Wcf.SelfHost.NinjectWcfSelfHost.Start()
at Ninject.Web.Common.SelfHost.NinjectSelfHostBootstrapper.Start()
at TestApp.Program.StartNinjectSelfHostFromPlugin(IEnumerable`1 psoWebService
s) in c:\Users\william.davis\Documents\Visual Studio 2013\Projects\Service\TestA
pp\Program.cs:line 80
经过大量重构后,我可以正常工作,但我不知道它是否正常 'correct.' 为了让它正常工作,我基本上必须在我的网络服务中创建一个新的 IKernel class并且还让它继承自 NinjectModule 并在其中配置绑定。为什么我需要多个内核才能实现这一点?我应该补充一点,如果我不需要 Ninject 这可以通过使用标准 ServiceHost