|
|
Depending on a web service’s processing, there may be times when you will want the service to perform specific processing each time the service starts or ends, when clients make requests to the service, or when a session starts or ends. In such cases, you can take advantage of the web service’s global.asax file. Actually, Visual Studio .NET creates three files with the global filename that use .asax within the file extension. Table 12.4 briefly describes each file’s contents.
Filename | Purpose |
---|---|
Global.asax | Contains a single-line entry that specifies the name of the code-behind file containing the statements that configure the application processing, and which lists the classes that the code inherits |
Global.asax.vb (or .cs) | Specifies the program statements the web service executes to perform startup or shutdown processing and additional processing the web service performs when it receives various client requests |
Globlal.asax.resx | An XML-based file that specifies resources the code requires |
As discussed, the Global.asax file contains a single-line entry that specifies the file’s programming language as well as classes the code inherits:
<%@ Application Codebehind="Global.asax.vb" _ Ä Inherits="DateService.Global" %>
Likewise, the Global.asax.vb file, shown in Listing 12.4, contains the programming statements that implement the web service’s startup and termination processing as well as the optional processing the web service performs when it receives a client request.
Listing 12.4 Global.asmx.vb
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs) ' Fires when the application is started End Sub Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs) ' Fires when the session is started End Sub Sub Application_BeginRequest(ByVal sender As Object, ByVal e As _ Ä EventArgs) ' Fires at the beginning of each request End Sub Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal _ Ä e As EventArgs) ' Fires upon attempting to authenticate the use End Sub Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs) ' Fires when an error occurs End Sub Sub Session_End(ByVal sender As Object, ByVal e As EventArgs) ' Fires when the session ends End Sub Sub Application_End(ByVal sender As Object, ByVal e As EventArgs) ' Fires when the application ends End Sub
Finally, the Global.asax.resx file, much like the Service1.asmx.resx file previously shown, contains XML-based entries that describe the resources the code requires.
|
|