Home > Articles > Programming > Windows Programming

  • Print
  • + Share This
This chapter is from the book

Web Services and ASP.NET

The coupe de grace brought by .NET (and ASP.NET especially) is support for programmable Web sites. In addition to simplifying the user interface aspect of Web development, ASP.NET's other huge contribution to the .NET platform is making it easy to produce Web services (which we have been discussing throughout this book).

During the short history of the Internet, there has always been a human interacting with Web sites, which has been a big boon to commerce in general. The Internet and the Web provide a whole new medium for research, information finding, advertising, and sales. However, this is only the tip of the iceberg.

There is a whole world of untapped resources, meaning that there is a whole world of problems to be solved—particularly those related to getting computers on the Web to talk to one another without human intervention and regardless of the type of computer platform being used. Sites with programmable services are called Web services in .NET parlance.

A Web service provides remote access to server functionality. For a number of years, those in both the COM camp and the Common Object Request Broker Architecture (CORBA) camp felt their particular component technology would revolutionize the Internet. The catch is that neither COM nor CORBA mixes very well with firewalls. The other problem is that neither protocol is ubiquitous between any two enterprises. Therefore although both these models are great for building software systems for the enterprise, they do not work between enterprises. Being able to programmatically contact another business and talk to it through the Internet has been stymied until now.

Although COM and CORBA are not viable Internet protocols, there is another protocol that everyone agrees on and is ubiquitous on the Internet—HTTP. In addition, XML has emerged as the de facto format for transmission. Together, XML and HTTP make up SOAP. SOAP makes writing programmatic Web sites possible.

In the .NET world, businesses will use Web services to expose programmatic interfaces to their data and business logic. Other businesses can then use those interfaces to communicate programmatically with the original business. Web services use HTTP and XML messaging to move data across firewalls—something that could not be done until recently. Because Web services are not tied to a particular component technology or object-calling convention, it does not matter which languages are used to write the programs and components. Microsoft puts the focus on interoperability, which will enable businesses of all natures to hook up through the Internet.

The idea of programmable Web sites is straightforward enough. Obviously, people have been getting information into Web sites (using browser interfaces). Web services allow computers to do the same thing. You just have to write your Web page correctly.

Web Methods and ASP.NET

When writing a Web forms application, the class you use derives from System.Web.UI.Page. When you write a Web service, the class you use derives from System.Web.Services.WebService. To add functionality to your Web service, your class includes methods marked with the WebMethod attribute. The beauty of ASP.NET is that it takes care of correctly mapping incoming HTTP requests onto calls on your object. (Technically, you can get by without using the WebService class. However, using WebService does give your application access to all of ASP.NET.)

Calling Web services from the client side is simple as well because the runtime provides proxy classes that wrap up the calls on the client side. A client-side proxy manages generating the right HTTP request to the server and parsing the response from the server.

Service Description Language and ASP.NET

Clients know the shape of the methods available on a Web service by reading its service description language (SDL). ASP.NET clients get a copy of a Web service's SDL by requesting the service's file (FOO.ASMX) and passing the SDL query string. At that point, ASP.NET uses reflection to generate an SDL file. The client code then uses the SDL to create a client-side proxy.

Invoking Web Methods

In addition to supporting Web service methods, ASP.NET supports invoking Web methods by one of three means: HTTP GET requests with parameters encoded within a query string, HTTP POST requests with parameters from input controls, and through a SOAP proxy (generated from a Web page's SDL).

  • + Share This
  • 🔖 Save To Your Account