Web Services • Chapter 10 |
451 |
Lets do a quick comparison:
■Both file types have a template, which includes references to the primary namespaces.
■.aspx pages have references to System.Drawing since their purpose is to generate a user interface.
■.asmx pages have references to System.Web.Services since their purpose is to generate an interface for external programs.
■You can add UI components and Data Connections to an
.aspx page.
■You can add Server and Data Connections to an .asmx page.
■.aspx pages usually begin with an @Page directive to designate: this is a Web Form.
■.asmx pages usually begin with an @WebService directive to designate: this is a Web Service.
■Using the wrong @ directive with the wrong type of file extension will generate an error.
While the client for an .aspx page is the Web browser, the client for an .asmx file is the Web server. Since they are used as programming interfaces and not directly utilized by the Web user, .asmx files should not contain any UI.To get a better understanding of how this all works, lets create an .aspx page that calls our “Hello” service.
1.In the Solutions Explorer, right-click the project name.
2.Select Add | New Item.
3.Select Web Form. Name the file helloPage.aspx.
4.While in design view, open the toolbox and drag onto the page a label and a button control from the selection of Web Forms (see Figure 10.8). While still in design mode double-click the new button.This will
generate event code in the code behind page (see Figure 10.9).
5.Right-click References in the Solution Explorer and select Add Web Reference.This is basically a graphical user interface (GUI) for the WSDL.exe command line utility.
6.When the Add Web Reference dialog opens (see Figure 10.10) click the link Web References on local server.