views:

156

answers:

2
  1. People says that libraries shouldn't have configuration files.
  2. I can't pass arguments to my WCF service class from its host (but I can from the client).
  3. I don't want to store the configuration on the client.
  4. What should I do?
+2  A: 

What are you asking? Are you talking about settings for the service (the server side), or the client?

Why can't you just use client-side config files like you do for other apps? This is the built-in, preferred way of doing things - why insist on not using it??

So again: what is it really that you're asking? Or what problem is it, that you're trying to solve, really?

  • for a service (server-side): store your bindings, behaviors, service endpoints etc. in the web.config (if hosting in IIS) or in the app.config of your service host (if NT Service or console app)

  • for a client: store your configuration in the main app's app.config that uses your library. If you want to, you can provide ready-made "client.config" and "bindings.config" files and then just simply add

    <system.serviceModel>
       <bindings configSource="bindings.config" />
       <client configSource="client.config" />
    </system.serviceModel>
    

to your client app's app.config - doesn't get much easier than that, really!

marc_s
My question wasn't about endpoint configuration, but your answer was useful for me. I just couldn't use the configSource parameter because my Visual Studio tells me: Warning The 'configSource' attribute is not declared.
Jader Dias
Yes, but that's a "false positive" - Visual Studio complains, but it raelly works - trust me, my systems use that EVERY day in production!
marc_s
A: 

I don't if i'm approaching this question properly...

The first point is totally arbitary, and sounds a bit fascist, or bolshie if you come from the Uk. Many different types of libraries come with configuration file. What other way would you do it? How would it work if you didn't have configure it, which is what .NET configuration model is built on.

Folk need to stop focusing on architecture buffs, P&P mechanics and programming purists, who often take extreme views based on some best, or minor design principles, above all else saying you should do this and do that.

On a purley technical footing, if your wanting to hide your configuration file, encrypt them. If you don't want to do that, but want them exposed to authorized users, then use protected storage.

Bob.

scope_creep
Not to say there aren't arguments against this, but putting a library's necessary configuration in the consuming code's configuration file results in fewer files to maintain. One config file per application.
gWiz