views:

2268

answers:

4

Aloha

I'm developing a web application (ASP.NET 3.5) that will consume a number of web services. I have created a separate dll-project for each web service: these projects contains the service reference and client code.

However, the calling website MUST have the <system.serviceModel> information (the <bindings> and <client> nodes) in it's web.config, even though this information is also in the dll's app.config file! I have tried copying the serviceclass.dll.config over to the bin directory of the website, but this didn't help.

Is there any way to centralize the configuration of a WCF client?

-Edoode

+2  A: 

I've only limited WCF experience, all with BasicHTTP bindings. But I'm allergic to WCF's xml files and have managed to avoid them thus far. I don't recomend this generally but I put the configuration details in my apps existing configuration store and then apply them programatically. E.g. With a Web service proxy I use the constructor for the Client that takes 'bindings'and 'endpoint' and programatically apply the settings to the bindings & endpoint.

A more elegent solution appears to be descibed here: Reading WCF Configuration from a Custom Location, but I haven't tried it yet.

it depends
Thank you. I've tried to code in the link you've supplied and it does exactly what I want.
edosoft
+2  A: 

It's possible to forgo xml config and build up the Binding and Endpoint classes associated with the service in the constructor or a custom "Service Factory". iDesign has some good information on this: http://www.idesign.net/idesign/DesktopDefault.aspx?tabindex=5&amp;tabid=11 (See In Proc Factory)

In their approach, you set attributes on your services to specify at a high level how they should work (ie [Internet], [Intranet], [BusinessToBusiness]), and the service factory configures the service according to best practices for each scenario. Their book describes building this sort of service: http://www.amazon.com/Programming-WCF-Services-Juval-Lowy/dp/0596526997

If you just want to share configuration XML config, maybe use the configSource attribute to specify a path for configuration: http://weblogs.asp.net/cibrax/archive/2007/07/24/configsource-attribute-on-system-servicemodel-section.aspx

Daniel
+3  A: 

From my experience, library projects never read app.config.

So you can really delete the file because it is not used. The library's host configuration is read instead, so that is the only place the endpoint and binding configuration should be.

AlexDrenea
exactly - if you have a DLL that's hosted / used by an app, only the app's config will matter. That's a .NET basic design decision. That's why the settings in the separate project DLL's app.config will not be used AT ALL.... :-(
marc_s
+1  A: 

Remember that a configuration file is is read by an executable that has an entry point. A library dll does not have an entry point so it is not the assembly that will read it. The executing assembly must have a configuration file to read.

If you would like to centralize your web configs then I would suggest you look into nesting them in IIS with virtual directories. This will allow you to use the configuration inheritance to centralize whatever you need.

Andrew Hare