Consume webservice from a .NET DLL - app.config problem

Posted by Asaf R on Stack Overflow See other posts from Stack Overflow or by Asaf R
Published on 2010-02-12T08:17:35Z Indexed on 2010/04/22 14:23 UTC
Read the original article Hit count: 544

Filed under:
|
|
|
|

Hi,

I'm building a DLL, let's call it mydll.dll, and in it I sometimes need to call methods from webservice, myservice. mydll.dll is built using C# and .NET 3.5.

To consume myservice from mydll I've Added A Service in Visual Studio 2008, which is more or less the same as using svcutil.exe. Doing so creates a class I can create, and adds endpoint and bindings configurations to mydll app.config.

The problem here is that mydll app.config is never loaded. Instead, what's loaded is the app.config or web.config of the program I use mydll in.

I expect mydll to evolve, which is why I've decoupled it's funcionality from the rest of my system to begin with. During that evolution it will likely add more webservice to which it'll call, ruling out manual copy-paste ways to overcome this problem.

I've looked at several possible approaches to attacking this issue:

  1. Manually copy endpoints and bindings from mydell app.config to target EXE or web .config file.
    Couples the modules, not flexible
  2. Include endpoints and bindings from mydll app.config in target .config, using configSource (see here). Also add coupling between modules
  3. Programmatically load mydll app.config, read endpoints and bindings, and instantiate Binding and EndpointAddress.
  4. Use a different tool to create local frontend for myservice

I'm not sure which way to go. Option 3 sounds promising, but as it turns out it's a lot of work and will probably introduce several bugs, so it doubtfully pays off. I'm also not familiar with any tool other than the canonical svcutil.exe.

Please either give pros and cons for the above alternative, provide tips for implementing any of them, or suggest other approaches.

Thanks,
Asaf

© Stack Overflow or respective owner

Related posts about webservice

Related posts about .NET