Creating/Consuming Web Service in VisualStudio.NET
Summary
The following namespaces support Web Service requirements:
| Namespace |
Notes |
| System.Web.Services |
Minimal and complete set of types required to
build a Web Service. |
| System.Web.Services.Description |
Allows you to programmatically interact with
WDSL. |
| System.Web.Services.Discovery |
Allows you to programmatically discover the
Web Services installed on a machine. |
| System.Web.Services.Protocols |
Defines a number of types that represent the
wire protocols used to exchange information between a Web Service and
its consumers. |
The core files of a VS.NET Web Service project are as follows:
| Web
Service Project File |
Note |
.asmx
.asmx.cs |
These files define the methods of the Web
Service. Each .asmx file has a corresponding Web
.asmx.cs file to hold
the code behind the form itself. |
| .disco |
This extension is short for 'DISCOvery of Web
Services' and contains an XML description of the web services at a given
URL. |
(VisualStudio.NET Project template is: ASP.NET Web Service)
Creating an ASP.NET Web Service in VisualStudio.NET is very easy and
straightforward. Here is how VisualStudio.NET lightens your load:
- VisualStudio.NET creates a new sub-Web in IIS as well as the associated
folder on the local HD.
- All you have to write is the method itself.
- VisualStudio.NET uses syntax highlighting and uses IntelliSense pop-up
windows to help write code more quickly.
- You do not have to create the WSDL document. VisualStudio.NET creates it
automatically based on the methods and parameters in your class.
- VisualStudio.NET offers easy access to the test harness.
- VisualStudio.NET automatically supplies other files such as a .vsdisco
file.
(VisualStudio.NET Project template is: ASP.NET Web Application)
A Web Service can be consumed (or used) by any type of application running on
virtually any computer running almost any software (in theory).
Creating an ASP.NET Web Application in VisualStudio.NET is very easy and
straightforward. Here is how VisualStudio.NET lightens your load:
- VisualStudio.NET creates the required files for you and the sub-Web in
IIS.
- You are able to create and add a Web Reference by simply navigating to it
in Server Explorer, popping up the Context Menu on your Web Services.
- VisualStudio.NET takes care of creating and compiling the proxy.
- You create the Web Forms application by simply dragging and dropping
controls onto the designer window.
- VisualStudio.NET uses syntax highlighting and uses IntelliSense pop-up
windows to help write code more quickly.
- You can view and test the Web Forms application within the IDE by simply
choosing View in Browser from the pop-up menu
on the Web Forms page.
Hints
If you come across some error such as "No Web References were found on
this page" when you attempt to add a reference to web service, or if
View in Browser generates HTTP errors, then you could try a few things:
- In many cases, VS.NET may have been installed before IIS was installed (
for example, I installed VS.NET on a machine with XP Home but then upgraded
the OS to XP Professional. In this scenario, IIS was installed after VS.NET
was installed). VS.NET upon installation will configure IIS with .asmx
files. To perform this configuration manually, just run aspnet_regiis.exe
utility which should be under C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705
directory.
- By default, dynamic discovery is not enabled leading to the "No Web
References were found on this page" when you attempt to enter the URL
to your *.vsdisco file in the Add
Web Reference dialog box. Locate your machine.config
file (on my machine it is under C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705\CONFIG)
and uncomment the following line (you may need to restart the machine):
<add verb="*" path="*.vsdisco" type="System.Web.Services.Discovery.DiscoveryRequestHandler, System.Web.Services, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" validate="false"/>