JavaScript Editor Javascript validator     Javascripts

Main Page

Previous Section Next Section

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:

  • Full implementation of the .NET Framework and Common Language Runtime (CLR), including the object-oriented architecture and all the base class libraries, as well as features such as caching, state, and data access

  • Nearly identical file and code structures

  • All source code files in plain text, which can be created in any text editor

  • Full support by Visual Studio .NET, with all its productivity features, including IntelliSense, code completion, and integrated debugging

  • Configurable on a global or application-wide basis using plain text configuration files

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.

The rationale for code-behind is that it provides a clean separation between the presentation and programmatic portions of an application. While this is extremely useful in the development of web pages, it is not really relevant to web services. However, since code-behind is the default coding technique for Visual Studio .NET (which offers so many productivity enhancements), code-behind becomes the de facto preferred technique. In addition, code-behind confers a performance advantage over inline code because the code-behind class must be precompiled for web services, while the .asmx file is compiled into a class the first time it is run.

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.

    Previous Section Next Section

    JavaScript Editor Javascript validator     Javascripts 
    online casino in Canada