views:

197

answers:

2

I am attempting to add a WCF web service to my project and each time I add a new web service it adds a new Service Behavior, new Service configuration, and changes the formatting of my web.config.

Is it possible to add a new WCF Web service (.svc extension) to my project without it changing my web.config file? I am willing to add the information I need manually.

+2  A: 

Yes, the behavior of the Add Service Reference part in Visual Studio is a major PIA - and it's not been improved a single iota in VS 2010, unfortunately :-((

And even more unfortunate, you cannot really tell the importer to leave your existing stuff alone - what I do is create a backup of my web.config, import the WCF service and let the importer mess up my web.config, and then I just slap my backup over the mess again and go about making the necessary additions manually.

One alternative is to use svcutil.exe on the command line - first of all, you can tell it to /noconfig and skip messing with your config (or you can output the recommend config into a separate config with a different name), and secondly, it'll happily create your client-side proxy service class in a C# or VB.NET file for you, ready to use.

But yes - of course you can add all the necessary information by hand!

In a typical client side config, the most important point is the <client> tag - just add whatever it is you need - using the "ABC of WCF" - (A)ddress, (B)inding, (C)ontract:

<client>
   <endpoint name="something-useful"
             address="your-address-on-the-server"
             binding="wsHttpBinding"  -- or whatever it is you're using
             contract="IYourServiceContract" />

That's the minimal client-side config you need. Anything else is just additional stuff, used when needed. This uses all the default settings for your binding, obviously.

Here are two really good videos that show how to do a lot of manual WCF configuration - sounds scary, turns out to be much easier than deciphering the mess the VS importer creates....

marc_s