I have a self hosted C# WCF service which creates 20+ endpoints for various purposes. Each is configured in the code itself with a few basic config items in the app.config of the service such as port and address. The service works great for the tested clients, but has not been widely tested.
I was a little leary of the standard wcf config file approach because I was afraid the end user would mess things up and hence did everything in code.
Is it a better idea to do the configuration in the config file because then the end user could customize it to their needs or is the in code approach sufficient for most needs?
One of the main benefits of WCF is the abstraction of the connection details away from the code. If you need to change any of the service parameters, doing so from the web.config can be done more readily, and without recompilation. You may need to change the “port and address,” for instance. If you are doing this from within the code, you would need to rebuild, which may be impractical. Further, I’m not sure why the end user would be messing with the web.config normally, unless it’s really necessary.
In short, unless you have a good reason not to use the config files, you should probably use them in order to get the full benefit of the abstraction that WCF provides.