c# - WCF ChannelFactory configuration outside of App.config? -


i've got windows service makes use of plugin system. i'm using following code in plugin base class provide separate configuration per dll (so it'll read plugin.dll.config):

string dllpath = assembly.getcallingassembly().location; return configurationmanager.openexeconfiguration(dllpath); 

these plugins need make calls wcf services, problem i'm running new channelfactory<>("endpointname") looks in hosted application's app.config endpoint configuration.

is there way tell channelfactory in configuration file or somehow inject configuration object?

the way can think of approach manually create endpoint , binding object values read in plugin.dll.config , pass them 1 of channelfactory<> overloads. seems recreating wheel though, , messy endpoint makes heavy use of behavior , binding configurations. perhaps there's way create endpoint , binding objects passing configuration section?

there 2 options.

option 1. working channels.

if working channels directly, .net 4.0 , .net 4.5 has configurationchannelfactory. example on msdn looks this:

execonfigurationfilemap filemap = new execonfigurationfilemap(); filemap.execonfigfilename = "test.config"; configuration newconfiguration = configurationmanager.openmappedexeconfiguration(     filemap,     configurationuserlevel.none);  configurationchannelfactory<icalculatorchannel> factory1 =      new configurationchannelfactory<icalculatorchannel>(         "endpoint1",          newconfiguration,          new endpointaddress("http://localhost:8000/servicemodelsamples/service")); icalculatorchannel client1 = factory1.createchannel(); 

as pointed out langdon, can use endpoint address configuration file passing in null, this:

var factory1 = new configurationchannelfactory<icalculatorchannel>(         "endpoint1",          newconfiguration,          null); icalculatorchannel client1 = factory1.createchannel(); 

this discussed in msdn documentation.

option 2. working proxies.

if you're working code-generated proxies, can read config file , load servicemodelsectiongroup. there bit more work involved using configurationchannelfactory @ least can continue using generated proxy (that under hood uses channelfactory , manages ichannelfactory you.

pablo cibraro shows nice example of here: getting wcf bindings , behaviors config source


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -