Introduction

We can now use ASP.NET to create Web Service that is based on industrial standards included XML, SOAP and WSDL.

ASP.NET Web Services support clients using HTTP-POST, HTTP-GET and SOAP protocols to invoke methods exposed, depends on your specific requirement you choose one method over the others. The main difference between HTTP-GET or HTTP-POST and SOAP is the data types supported by SOAP is much richer because SOAP used XSD schema to represent complex data types.

Here are samples codes I use to test the building of ASP.NET Web Service:

Step 1: Create the ASP.NET Web Service Source File

ASP.NET Web Service file name has extension asmx and my file is named MyWebService.asmx, source is listed as follows:

File: MyWebService.asmx

The page directive WebService is required and class is the name of the .NET Class to expose the Web Service, each method exposes as Web Service Class Method need to have a declarative attribute statement [WebMethod()] in front of it. Here the .NET Class implementation is included in the same file with ASP.NET Web Service file but it is not mandatory and we can choose to include an external .NET Assembly to implement the service as the following example:

File: MyWebService2.asmx

The file MyWebService2.asmx is referencing another .NET AssemblyMyWebServiceImpl which is located under the /bin ASP.NET Application sub-folder (note that the default location for Assemblies in ASP.NET is /bin sub-folder under each ASP.NET Applications). The source of .NET AssemblyMyWebServiceImpl is written by C# and is listed as follows:

The following sections I will continue use MyWebService.asmx as my experimental Web Service.

Step 2: Create the ASP.NET Web Service Clients

There are many ways to consume Web Services and have three examples. The first one uses HTTP-POST protocol and it has advantage to coexist with today’s application quite well and use HTTP-GET is similar and I let reader to try it. The second one uses SOAP Proxy Client Object generated by WSDL utility and it provides programmers with their familiar object modal that they call methods provided by the generated Proxy Interface. The final one uses SOAP standard request message and it parses SOAP response message with the help of XMLHTTP COM object that is installed by Microsoft XML Parser 3.0.

Client use HTTP-POST Method

The example is an ASP.NET page TestWebService.aspx and source listing as follows:

File: TestWebService.aspx

The ASP page accepts parameters from browser and calls the Add method of the Web Service MyWebService via the HTTP-POST protocol, the result will be XML message and need further parsing by the client application. To parse the response, client can use either Java XML parser in applet or use IE5’s DOM Object.

The following is an example of XML response when parameters a=1, b=2 are inputted:

Summary

There are many difference implementations for SOAP Service but the standard is there and we can start to build some useful applications on it. Although ASP.NET or SOAP web services have many nice features, if you want to consume the exposed Web Services in you clients, please make sure you have the latest libraries installed because standards continue evolving and all vendors try their best achieve the edge in such open standards war.

Share

About the Author

I am always interested in finding innovative ways for building better applications and founded a technology company since 2003. Welcome to exchange any idea with you and if I am not too busy before deadline of projects, I will reply your emails. Also, if you willing to pay for consulting works and customized software development, you can leave me message.