Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ninject WCF bootstrapper registering multiple services

Tags:

c#

wcf

ninject

I'm having a problem getting the wcf extensions to work with more than one self host bootstrapper. With one my services are created by ninject fine (per call), but when I add another I get an exception that the ChannelDispatcher is unable to open its IChannelListener, the inner exception states that a registration already eixsts for URI 'net.tcp://localhost:901/MyService'.

My registration code looks like this:

var myService= NinjectWcfConfiguration.Create<MyService, NinjectServiceSelfHostFactory>();
_myServiceHost= new NinjectSelfHostBootstrapper(() => _kernel, myService);

var myService2= NinjectWcfConfiguration.Create<MyService2, NinjectServiceSelfHostFactory>();
_myService2Host= new NinjectSelfHostBootstrapper(() => _kernel, myService2);

_myServiceHost.Start();
_myService2Host.Start();

Both services have the correct sections in the config file and they both have different endpoint URIs with different ports. The same config works fine if I wire all of this up manually.

Does anyone have a clue here? Bit stumped...

Cheers

like image 391
user303754 Avatar asked Jul 02 '13 12:07

user303754


1 Answers

I ran into this issue just now, the solution is to have one Bootstrapper with all configurations in its params:

var myService= NinjectWcfConfiguration.Create<MyService, NinjectServiceSelfHostFactory>();
var myService2= NinjectWcfConfiguration.Create<MyService2, NinjectServiceSelfHostFactory>();

_myServicesHost= new NinjectSelfHostBootstrapper(() => _kernel, myService, myService2);

_myServicesHost.Start();
like image 76
MatthewC Avatar answered Sep 22 '22 11:09

MatthewC