Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically configuration of endpoints vs. web/app.config

Has any put much thought into this? Personally, I think managing endpoints in configuration files are a pain. Are there any pros/cons to doing one over the other?

like image 309
user24985 Avatar asked Apr 09 '26 09:04

user24985


2 Answers

Only points in favour of configuration files from me.

Managing endpoints in configuration files mean that you don't have to update your application if (or perhaps I should say when) the endpoints change.

You can also have several instances of the application running with different endpoints.

like image 95
ChrisF Avatar answered Apr 10 '26 22:04

ChrisF


I tend to like the config approach myself too, other than the config file can get pretty big.

The one thing I have noticed with WCF configuration is that there is a lot of stuff that you can do from code that you can't do in XML config without adding your own custom extensions. In other words, doing config in code will allow more flexibility, of course you could also just code your own extensions and use those from configuration.

However, do note that there is what I would consider a 'bug' in Visual Studio that if you start making your own extensions and including them in XML, then VS won't like your config file any more and will tag them as errors, and then if you try to add a new service through the wizards, it will fail to add the endpoint to the configuration.


This is sort of a followup to my own answer:

After months of having everything in xml configuration, I'm changing everything to construct the endpoints and bindings in code. I found a really good case for having it in code;

When you want to have a deployable / sharable .dll that contains WCF clients.

So for example if you have a CommonClients.dll that contains all your WCF interfaces and contracts to communicate with some remote server, then you don't want to also say "here is 100 lines of xml that you also have to drop into your app.config for every client to make it work". Having it all constructed in code works out much better in this case.

There is also a "feature" of .NET 3.5 where if you have some wcf extensions, you have to specify the fully qualified assembly name. This means that if your assembly containing the extensions changes the version nnumber, you have to go change the assembly name in the config file too. It is supposedly fixed in .NET 4 to use a short assembly name and not require the full name.

like image 45
CodingWithSpike Avatar answered Apr 10 '26 21:04

CodingWithSpike