5StringRyan
5StringRyan

Reputation: 3634

Porting WCF Service Web.config to Windows Service App.config

I've been working with about a dozen WCF Services that have been deployed to various machines with IIS. All binding/configurations have been kept in the usual "web.config" file that was created to keep the services more configurable and keep the service code itself more clean. However, I've just recently been tasked with creating a Windows Service to host these WCF Services. One question that I have is, do I just copy all the settings from the web.config file to the App.config file for the windows service? Or do I need to reconfigure all the endpoints/bindings/etc. using a different format in the App.config file? I've never created a windows service before and not 100% sure what I need for setup once I've created the Windows Service Host. Thanks in advance.

Upvotes: 0

Views: 892

Answers (2)

Cheeso
Cheeso

Reputation: 192437

I always thought the .NET config model didn't fit well with WCF service configuration.

There's a way to teach WCF to retrieve its configuration from an alternative location. I like to set it so that the WCF service retrieves its configuration information from ServiceName.config rather than web.config or AppName.exe.config. This solves the problem of repeating elements mentioned by Harper Shelby.

Here's a full explanation and some code.

Using that custom service host, moving a WCF service from IIS to a self-hosted model is really simple.

See also, WCF Configuration - Split it out of app.config

Upvotes: 1

Harper Shelby
Harper Shelby

Reputation: 16585

The WCF configuration elements in web.config should translate directly to app.config. I've cut and pasted web.config elements like this in the past. The only thing to watch out for is that neither web.config nor app.config like certain elements repeating, so if you're merging configuration data from multiple web.config files, you'll have to ensure that you don't repeat sections that should only exist once.

Upvotes: 1

Related Questions