Web Services Provider

In this section, we describe how to develop a web service, first from the point of view of service providers and then of the consumers.

Web Services providers implement web services and advertise them so that the clients can discover and make use of the services. Because web services run on top of HTTP, there must be a web server application of some sort on the machine that hosts the web services. This web server application can be Microsoft Internet Information Services (IIS), Apache, or any other program that can understand and process the HTTP protocol. In our examples, we use Microsoft IIS, since that is the only web server currently supported by .NET.

Web Service Provider Example

We will be building a web service called PubsWS to let consumers get information from the sample Pubs database. All data access will be done through ADO.NET, so make sure you’ve read Chapter 5 before attempting the examples.

Creating a web service is a three-step process.

  1. Create a new asmx file for the web service. This must contain the <% webservice ... %> directive, as well as the class that provides the web service implementation. To the Web Service clients, this asmx file is the entry point to your Web Service. You need to put this in a virtual directory that has the executescripts permission turned on.

  2. Inherit from the WebService class of the System.Web.Services namespace. This allows the derived class to access all the normal ASP objects exposed in the WebService base class. ...

Get .Net Framework Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.