Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Microsoft C# Professional Projects - Premier Press.pdf
Скачиваний:
177
Добавлен:
24.05.2014
Размер:
14.65 Mб
Скачать

640 Project 5 CREATING A WEB PORTAL FOR A BOOKSTORE

Summary

In this chapter, you learned about distributed applications. Distributed applications are scalable applications in which data is shared across applications. Therefore, distributed applications include applications built on different platforms or by using different programming languages. To create a large-scale business solution, it is essential that you integrate these applications. Integration of applications built on various platforms is made simpler with the use of Web services.

A Web service is a reusable component, such as a method, that can be used by any Web application running on the Internet. These applications are called Web service client applications. An application that hosts the Web service is called a Web service provider application.

Next, you learned about the architecture of a Web service.The Web service architecture includes a four-layered model. These layers are the data layer, the data access layer, the business layer, and the listener layer. Based on this architecture, you learned about the working of the Web service.

Next, you learned about the role of XML, WSDL, SOAP, and UDDI in a Web service.Based on this knowledge about a Web service, you learned to create a simple Web service using Visual Studio .NET.

Chapter 29

Developing

Web Services

642 Project 5 CREATING A WEB PORTAL FOR A BOOKSTORE

In the preceding chapters, you looked at the case study and design of the Web site of Bookers Paradise. In addition, you were introduced to the basics of an ASP.NET Web service. Based on the knowledge about Web services, you learned to create a sample Web service by using Visual Studio .NET. This chapter dis-

cusses how to create a Web service for Deepthoughts Publications.

Creating a Web Service for

Deepthoughts Publications

A Web service for Deepthoughts Publications provides information about books published at its publishing house. This information is displayed on the Web site of Bookers Paradise. In addition to searching for information about all the books published by Deepthoughts Publications, a user can search for selected books based on criteria.

To start with, you can create a Web service by using the ASP.NET Web Service template provided by Visual Studio .NET. Refer to this Web service as DTWebService. To create the Web service, perform the following steps:

1.On the File menu, point to the New option.

2.In the displayed list, select the Project option. The New Project dialog box is displayed.

3.In the Project Types: pane, select the Visual C# Projects option.

4.In the Templates: pane, select the ASP.NET Web Service option.

5.In the Location: text box, type the name of the Web service as

DTWebService.

6. Click on the OK button to create the DTWebService Web service.

Figure 29-1 shows the New Project dialog box for DT WebService.

DEVELOPING WEB SERVICES

Chapter 29

643

 

 

 

 

FIGURE 29-1 The New Project dialog box for DTWebService

Visual Studio .NET creates the Web service and the default files in the Web service. I have discussed the default files generated by Visual Studio .NET for a Web service in Chapter 28, “Exploring ASP.NET Web Services,” in the section “Web Services in the .NET Framework.”

After creating the Web service, add a short description of the Web service. This will help any user looking for a similar Web service. To write a short description, add the following code at the beginning of the Web service.

[WebService (Namespace=”http://LocalHost/DTWebService/”, Description=”A service

displaying catalogs of Deepthoughts publisher”)]

Because the Web service that you create needs to connect to a database, you need to create a data connection object. To create a data connection object to connect to a database, perform the following steps:

1.In the Server Explorer window, expand the Servers node.

If the Ser ver Explorer window is not displayed, you can select the Server Explorer option on the View menu.

When you expand the Servers node, a list of the available SQL servers is displayed.

644 Project 5 CREATING A WEB PORTAL FOR A BOOKSTORE

2.Browse for the DTDB database and drag the DTCatalog table to the Service1.asmx page.

Visual Studio .NET automatically adds sqlConnection and sqlDataAdapter components to the Service1.asmx page. When the sqlConnection and sqlDataAdapter components are added, you need to create a dataset that accesses data from the DTDB database. To do this, perform the following steps:

1.On the Data menu, select the Generate Dataset option. The Generate Dataset dialog box is displayed.

2.In the Choose a dataset: group box, select the New radio button.

3.Specify the name of the dataset as dsDetails1.

4.Check the Add this dataset to the designer window check box.

5.Click on the OK button to close the Generate Dataset dialog box.

The dataset with the name dsDetails1 is added to the Service1.asmx page. Figure 29-2 shows the sqlConnection, sqlDataAdapter, and dataset components added to the Service1.asmx page.

FIGURE 29-2 The Service1.asmx page with the components added

Once a Web service is created and the components are added, you can add Web methods to it. Web methods are required to provide the functionality to the Web site. The following section discusses the Web methods in the Web service of Deepthoughts Publications.