Page 228 - DCAP312_WEB_TECHNOLOGIES_II
P. 228
Web Technologies-II
Notes From a developer's point of view, if you have ever written application logic, you have the
required skills to author ASP.NET Web Services. More importantly, if you are at all familiar
with ASP or ASP.NET application services, (application state memory, and so on) you can also
leverage these skills when you build ASP.NET Web Services.
A Web Service in .Net consists of an .ASMX page that either contains a class that provides the
Web Service functionality or references a specific external class that handles the logic in an
external class file. Classes are standard .Net classes and the only difference is that every method
that you want to expose to the Web is prefixed with a [Web Method] attribute. Once the .ASMX
page has been created the Web Service is ready for accessing over the Web. .Net provides a very
useful information page about your Web Service showing all the methods and parameters along
with information on how to access the Web Service over the Web. You can also use this page
to test basic operation of your Web Service without calling the Web Service with a ‘real’ client.
The .Net Web Services that run over HTTP can be called in three different ways:
• HTTP GET Operation: You can pass parameters to a Web Service by calling the ASMX page
with query string parameters for the method to call and the values of simple parameters
to pass.
• HTTP POST Operation: Works the same as GET Operation except that the parameters are
passed as standard URL encoded form variables. If you use a client such as wwIPStuff
you can use AddPostKey () to add each parameter in the proper parameter order.
• SOAP: this is the proper way to call a Web Service in .Net and it is also the way that .Net
uses internally to call Web Services.
The GET and POST operations are useful if you need to call a Web Service quickly and no SOAP
client is readily available. For example, in a browser based client application it may be easier to
use GET and POST instead of constructing and parsing the more complex SOAP headers that
are passed back and forth in a SOAP request. But with a proper SOAP client in place SOAP
provides the full flexibility of the protocol, where GET and POST operations have to stick to
simple inputs and outputs. Among other things that you can do with SOAP is pass complex
objects and data over the wire and for these operations to work you need to use SOAP.
Behind the scenes there are three major components that make up a Web Service:
• The Web Service on the Server side
• The client application calling the Web Service via a Web Reference
• A WSDL Web Service description that describes the functionality of the Web Service.
11.1 Creating Web Services
Creating a Web service in Visual Studio .NET is very easy. ASP.NET server side knowledge
allows developers to create web services and the .NET framework provides a sophisticated
position of tools and rules to devour web services.
Let us start by creating the Hello world web service. We will create the web service using asp.
net and visual basic language. The IDE we will use is Visual Studio. NET. We can also create
an ASP.NET Web Service in C# programming language using Visual Studio .NET.
To create the web service, open Visual Studio and select File-> New Web site from the menu.
Make sure Visual Basic is selected in the language box and HTTP in the location box. Select
ASP.NET Web service from the template list. Enter the name as http://localhost/HelloService
as shown in Figure 11.1 and click OK.
222 LOVELY PROFESSIONAL UNIVERSITY