X
Business

Consuming ASP.NET Web services with ASP

The exodus from Visual Studio 6.0 to .NET has begun for most developers. But with this new coding model comes decoupled services in the form of Web services.
Written by Phillip Perkins, Contributor
The exodus from Visual Studio 6.0 to .NET has begun for most developers. But with this new coding model comes decoupled services in the form of Web services.

However, if you still have to maintain and develop using standard ASP, you'll have to develop systems that interact with .NET Web services. With the Microsoft SOAP Toolkit 3.0, this interaction is simple to implement.

Creating an ASP.NET Web service
It's simple to create an ASP.NET Web service within the Visual Studio .NET IDE. If you don't have Visual Studio .NET, you can also use the free ASP.NET Web Matrix IDE available at the ASP.NET site.

Create an ASP.NET Web service project called Hello. This will also become your project's namespace. Within this project, add a Web service called HelloWorldService. At this point, the IDE usually adds a sample method called HelloWorld, which returns the string "Hello World".

After you complete these tasks, your code should look similar to Listing A.

Test your code by navigating to your Web service page. Invoke the HelloWorld method of your Web service. If you get the "Hello World" string return value, you can proceed to the next step: creating an ASP.NET Web service consumer.

Consuming an ASP.NET Web service
The Microsoft SOAP Toolkit 3.0 provides the mechanisms for consuming a SOAP Web service. The MSSOAP.SoapClient object consumes the Web service functionality in an object-oriented style.

When you initialize the client using the WSDL for the Web service and the service name, the SoapClient object absorbs the available service methods. For example, your Web service has a method called HelloWorld. When you initialize the SoapClient object, the HelloWorld service method is now a method of the SoapClient object. You can see this in Listing B.

You initialize the SoapClient object with the mssoapinit method, which takes two parameters: the path to the WSDL file and the name of the Web service. One of the benefits of ASP.NET Web services is that you simply point to the .asmx file of your Web service appended with "?WSDL". This returns the WSDL of the service. And, to use the service method HelloWorld, you need to call the HelloWorld method of the SoapClient object. This simple ASP page will prepare an HTML page with the text "Hello World".

Cost of creating and consuming an ASP.NET Web service
It's essentially free to consume ASP.NET Web services when you use the free .NET Framework download, the free Microsoft SOAP Toolkit download, and the free ASP.NET Web Matrix. You can build standard ASP pages using a simple text editor. The only thing that you would need to pay for is the operating system that supports IIS 5.0 or above. This is available in Microsoft Windows 2000, Microsoft Windows XP Professional, or Microsoft Windows 2003.

Now you should be able to expand upon my simple examples and create your own .NET Web service consumers using standard ASP.

Phillip Perkins is a contractor with Ajilon Consulting. His experience ranges from machine control and client server to corporate intranet applications.

Editorial standards