views:

170

answers:

3

A little background:

I'm creating a set of adapters to allow communication with mobile devices over different cellular networks. This will be achieved using a class factory pattern. At least one of the networks requires a service reference to communicate with their devices through a web service.

So far I've got 3 assemblies so far which represent:

  • An assembly which contains the main adapter library: this contains
    • The interface definition for each of the adapters
    • Base classes
    • The class factory to instantiate the specified adapter at runtime.
  • An assembly for each network adapter implementation.
  • An assembly that contains my main application.

Given that I don't want to be adding service references and their configuration to the main application assembly [as that's not relevant to the main application], how do I force each assembly's service reference to get its configuration from its own app.config?

If I have the service reference configuration in the main app.config, everything works just fine, but if I move the configuration to the adapter's app.config everything stops working throwing the following exception at the point where I new up the Soap1Client.

"Could not find default endpoint element that references contract 'MobileService.Service1Soap' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element."

A: 

I don't believe there is a built in .NET way to accomplish this. However you should be able to accomplish it by writing some code to parse each referenced assembly's .config file.

Here is a sample using assembly specific configuration files that should point you in the right direction: http://www.bearcanyon.com/dotnet/#AssemblySettings.

I've done something similar in a .NET Winforms app and it worked out well.

I checked out the per assembly configuration settings that article alludes to and I don't see how it can work in this situation. I need to find a way to control the configuration file the service reference is referencing.
BenAlabaster
+1  A: 

You can set all the options programatically.

leppie
+1  A: 

In the end, I just removed the service reference and added a web reference [i.e. did it the 2.0 way]. For some reason the web reference will access its own app.config instead of the main application's app.config.

Far easier than the alternative...

BenAlabaster