How to make dynamically generated .net service client read configuration from another location than

Posted by Bryan on Stack Overflow See other posts from Stack Overflow or by Bryan
Published on 2010-05-12T18:14:59Z Indexed on 2010/05/12 18:24 UTC
Read the original article Hit count: 467

Filed under:
|
|
|
|

Hi,

I've currently written code to use the ServiceContractGenerator to generate web service client code based on a wsdl, and then compile it into an assembly in memory using the code dom. I'm then using reflection to set up the binding, endpoint, service values/types, and then ultimately invoke the web service method based on xml configuration that can be altered at run time.

This all currently works fine. However, the problem I'm currently running into, is that I'm hitting several exotic web services that require lots of custom binding/security settings. This is forcing me to add more and more configuration into my custom xml configurations, as well as the corresponding updates to my code to interpret and set those binding/security settings in code.

Ultimately, this makes adding these 'exotic' services slower, and I can see myself eventually reimplementing the 'system.serviceModel' section of the web or app.config file, which is never a good thing.

My question is, and this is where my lack of experience .net and C# shows, is there a way to define the configuration normally found in the web.config or app.config 'system.serviceModel' section somewhere else, and at run time supply this to configuration to the web service client?

Is there a way to attach an app.config directly to an assembly as a resource or any other way to supply this configuration to the client?

Basically, I'd like attach an app.config only containing a 'system.serviceModel' to the assembly containing a web service client so that it can use its configuration. This way I wouldn't need to handle every configuration under the sun, I could let .net do it for me.

Fyi, it's not an option for me to put the configuration for every service in the app.config for the running application.

Any help would be greatly appreciated.

Thanks in advance! Bryan

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET