I don't know about you, but I despise the Add Web Reference feature in Visual Studio, especially in Visual Studio 2005. If you use it or have used that feature you're probably aware of the junk it adds to your project, such as the settings.settings file and additional entries into your config file (It adds a section for <applicationSettings> which is different from the standard <appSettings> section we already have. Who decided that was a good idea? And jeez, God knows we all need yet even more stuff shoved into our config files).
The thing that Add Web Reference ultimately does is generate the web service proxy file for you, which you can see if you turn on Show All Files for your project. The proxy file is really the only relevant item that we need to consume a web service.
To combat this problem and keep my Visual Studio projects clean, I wrote a little utility called the Web Service Proxy Generator (WSProxyGen) that will, uh, generate a web service proxy file (I know, very original). The need to do this arose from the last project I was on, so awhile back I finally sat down one night and wrote this thing and have been using it on my projects ever since. I also make sure all the developers on my teams use it as well to ensure consistency in all projects. Yes, I'm just now getting around to blogging it, leave me alone ;-)
Below is a picture of what WSProxyGen looks like. That's it. Only one form and fairly dead simple to use. It invokes the wsdl tool (from the SDK) to do the work and is completely configurable.
Even though most of WSProxyGen is self-explanatory, allow me to elaborate on a couple things. First is that you can set default values for all the textboxes and checkboxes; just open the WSProxyGen config file and edit the appropriate key values.
Notice the checkbox for "Remove entity types". This is very handy when you need to create a web service proxy for your own web service but you want to use the same types on both endpoints. For example, if your web service exposes a GetCustomer method that returns a Customer entity, the Customer type in your entity model is different from the Customer type returned from your web service (because of the web service namespace). But since the Customer entity is yours and you control its type, there is no need for those to actually be different types. That's where "Remove entity types" comes in. Checking this option will completely remove all the entity types from the web service proxy file. This allows you to add additional using statements to the web service proxy so that the Customer entity in your entity model and the one returned from the web service is the same type (for example, if your Customer entity resides in the MyApp.Entities namespace, you can add that namespace in the "Additional using statements" texbox and you'll be good to go).
The other thing is the option to get the web service URL from <appSettings> in your config file. Checking this option and supplying the key tells WSProxyGen to rewrite the constructor in the web service proxy to read the URL from the config file.
Also notice that for the language WSProxyGen says "VB not yet supported". It should read "VB will not be supported unless someone else does it because I probably won't find the time to do it" ;-)
And there you have it. Once you click the "Generate Proxy" button (large and in charge) your web service proxy file will be generated and put into the folder you specified. From there you can add it to the appropriate place in your Visual Studio project, write tests around it, and consume it as if there was no tomorrow.
You can get WSProxyGen here. It includes all the source code for anyone interested.
Oh, one last thing. I would advise
adding WSProxyGen as an external tool from within Visual Studio so that it's always at your fingertips (no need for arguments or anything, just give it a title and the command). Enjoy!
Print | posted on Wednesday, April 04, 2007 2:35 PM