Chapter 16. Creating Web Services
Chapter 15 provided an overview of web services, which are basically web applications with no user interface. Web services allow an application to make method calls against another application over the Internet as though it were calling a local dll.
There are two broad aspects to web service development: creating the web service and consuming the web service. This chapter covers the creation of web services. Chapter 17 covers the creation of web service client applications, also known as consumers.
Although a web service has no user interface and no visual component, the architecture and files used to create a web service are very similar to those used to create a web page, which are described in detail in Chapter 2 through Chapter 6. Some of these similarities include:
That said, web pages and web services are conceptually very different. A web page entails an interface designed for interaction with a person sitting at a web browser. A web service, on the other hand, consists only of methods, some of which are available for remote calls by client applications.
A web service can be coded inline, in a single file with an extension of .asmx. Alternatively, the application logic of the web service can be segregated into a code-behind file, which is the default behavior of Visual Studio .NET. While code-behind is generally preferred, especially for large projects, both methods will be demonstrated in this chapter.
Whether using an inline or code-behind architecture, the .asmx file is the target entered into the browser for testing or referenced by the utilities that create the proxy dll. (Recall from Chapter 15 that the client application actually makes calls to a proxy dll. Creation of this proxy dll will be described in detail in Chapter 16.)
As a first step in understanding how web services work, we will create a simple web service, called StockTicker, using any favorite text editor. In subsequent sections of this chapter, we will create the same web service using Visual Studio .NET.