Publishing WCF Web Services

RyanAndres used Ask the Experts™
I have a solution with 2 projects: a wcf web service and a winforms application that consumes the service.

Everything works great in local development mode since the service runs on the visual studio and the app.config for the winforms application contains the endpoint to localhost and some random port.

What is the proper way to publish the web service AND the consuming application?

Publishing the web service to an IIS server requires me to update the endpoint for the application and if I want to run in locally again I have to update the endpoint. Is there an easier way to publish to an external location and switch between a local environment?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Not if you want to use all the automagic stuff that the IDE or svcutil does for you when you create your service clients.  However, a quick search and replace of the app.config file for localhost:[portnumber] to whatever your deployment server is should be a quick way to configure everything.
Aaron JabamaniTechnical Architect

If you have some tools to create deployment for your applciation, you can do this automatically.

Else you name the server as "localhost" that should work in your local as well as in your deployment server.


I used the conditional #if and #else to create my endpoints programatically.

The #if block will use the endpoint with the 'localhost' address in the app.config file and the #else block will use my specified path in the contructor.

This method works for me but is it a proper implementation?
#if Debug
            _hrClient = new HrClient();
            _hrClient = new HrClient("BasicHttpBinding_IHr", "");

Open in new window

Technical Architect
Nope. What happens if want to test this in other than 2 machine.

Manual Step, either of below way you have problems.
Either you have to manually like you are doing
Else you can have two separate config files and replace the whole file.

Use some tools like(MSBUILD) to compile/deploy.
I agree with apeter, you want to keep as much of the configuration out of your compiled code as possible.

I guess I don't really understand the issue here?  with all of the search and replace technology we have available that uses advanced techniques (like wildcards and regex) why is this a huge issue?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial