“Add Web Reference” and “Add Service Reference” differences

I know when we moved from Visual Studio 2005 to Visual Studio 2008, so of you might have noticed we cannot see the “Add Web Reference” option on the right click context menu for the Project, while we are trying to add Web Reference.

Some of them simply blame with out idea, like What microsoft has done with it? Well before going further on What happened to it? Lets see what are the different between these two.

Add Web Reference is a wrapper over wsdl.exe and can be used to create proxies for .NET 1.1 or 2.0 clients. Of course this means when you are pointing to a WCF service you have to be pointing to an endpoint that uses basicHttpBinding (as I was). While adding web Service (*.asmx) files also we would be using this tool, which generates a Wrapper for the target Web Service from it’s WSDL.

Additionally it makes entries to the Web.config or app.config, in <applicationSettings> section. This can be customizable when we toggle between Testing and Production copy of web services.

Add Service Reference is a wrapper over svcutil.exe and also creates clients proxies (and additionally web.config entries). These proxies, however, can only be consumed by .NET 3.0+ clients.

This option will create the <serviceModel> <client> entries in to the Web.config or App.config

If you try to add a *.asmx (ASP.NET Web Service), it will create a simple basicHttpBinding configuartion for the Web Service. Why it’s creating WCF like entry for *.asmx web services mean, since it’s a Simple /Generic ASP.NET Web Service, and it follows the same binding configuation similar to “basicHttpBinding”.

This is an interesting way to add reference for a web service, so that we are doing it keeping in mind a future expandability scenario. In future we might upgrade our web service to a WCF Web Service, so that our web service code needs minimal amount of change only. We will point out “binding” cinfiguation for ASP.NET Web Service to new WCF WebService location and make some necessary configuarion entries. In most of the cases it will work with out any issues. Still yet to look in to other different scenarios.

Tip to get “Add Web Reference” menu in “Visual Studio 2008”.

1.) In Visual Studio 2008, right click on the project and select “Add Service Reference”, a window like in below screen shot will appear in your screen.
WS100001


2.) Click on “Advanced” button. (will get a similar popup)
WS100002


3.) Click on “Add Web Reference” option
WS100003


4.) Enter the web service Url and click on Go, will fetch the WSDL from the URL and specify a proper name space name or continue with defaultly mentioned one and click on “Add Reference”.  Viola!!! you have added a web reference.
WS100004

NOTE: You can see “Add Web Reference” not visible some type of project templates only.

For example a .NET 3.5 – Class Library etc, and for remianing projects it will be enabled default. So do not get confused.

Conclusion

This is what happened in reality, you don’t have to confused “Arey, where is that Add Web Reference yaar??”, it’s there only. He is playing hide and seek with you.

I hope this was informative. Have fun!!!!. Happy Coding !!!.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.