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

DEVELOPING WEB SERVICES

Chapter 29

665

 

 

 

 

Data integrity

Data privacy

Data availability

Among all these attributes, authentication is the most important attribute. To provide security to your Web service, you need to have a secure mechanism for authentication. Authentication is defined as the process of verifying the details of the user attempting to access the Web service. This verification is done on the basis of the information stored about the user. This information may include a password, an ID, or a thumbprint. These credentials stored for a user are called principal. However, to avoid a situation in which an unauthorized user tries to access the Web service by using the password assigned to an authorized user, you need to carefully decide the authentication credentials for your Web service.

Summary

In this chapter, you learned how to create the DTWebService Web service. While creating the Web service, you added the required Web methods to the Web service. These Web methods include AcceptDetails(), GenerateOrder(),

SearchALL(), SrchISBN(), SrchTitle(), SrchCategory(), and SrchAuthor(). In this

way, you can also create a Web service for Black and White Publications.

After adding the Web methods to the DTWebService Web service, you tested the Web service in the Internet Explorer window. Finally, you learned to secure a Web service.

This page intentionally left blank

Chapter 30

Developing Web

Service Clients

668 Project 5 CREATING A WEB PORTAL FOR A BOOKSTORE

In the preceding chapter, you created a Web service for Deepthoughts Publications.However, to access the Web service, you need to create a Web client application. In this case, the Web client application is the Web site for Bookers

Paradise.

In this chapter, you will learn to create the Web service client application. Creat-

ing the Web service client application includes creating the Web forms required

 

 

Y

for the Web site. In addition, you will learn to add code to the Web forms.

 

L

 

F

Creating a Web Service Client

 

M

 

Application forABookers Paradise

The Web site for BookersEParadise displays the information about the books pub-

lished by Deepthoughts Publications and Black and White Publications.The user

T

 

 

can choose to view information about all the books or selected books on the Web site. In addition to viewing information, the user can select a book to order.

When a user orders a book, the details of the book and the customer are added to the database of the publisher. Before writing the code for the client application, you will create the Web forms for the application.

Creating the Web Forms for the Bookers Paradise Web Site

You have seen the design of the Web forms for the Bookers Paradise Web site in Chapter 27, “Project Case Study and Design,” in the section “Web Forms Design.” However, in Chapter 27, you did not create the forms. The following sections discuss the creation of the Web forms used in the Bookers Paradise Web site.

Team-Fly®

DEVELOPING WEB SERVICE CLIENTS

Chapter 30

669

 

 

 

 

Creating the Main Form

As already discussed in Chapter 27, the Main form consists of four label controls, one button control, five hyperlink controls, one list control, one text box control, and two table controls. To add these controls to the Main form, drag these controls from the Web Forms toolbox and change the properties of the controls.Table 30-1 shows the properties that you need to change for the controls.

Table 30-1 Properties for the Controls Added to the Main Form

Control

Property

Value

Label1

ID

Label1

 

Text

Browse

 

Font

Verdana

 

ForeColor

Purple

 

BackColor

#FF80FF

Label2

ID

Label2

 

Text

Bookers Paradise

 

Font

Monotype Corsiva, XX-Large

 

ForeColor

Purple

 

BackColor

Transparent

Label3

ID

Label3

 

Text

Your Online Bookstore…

 

Font

Monotype Corsiva, Larger

 

ForeColor

Purple

 

BackColor

Transparent

Label4

ID

Label4

 

Text

About US…

 

Font

Monotype Corsiva, Larger

 

ForeColor

Purple

 

BackColor

Transparent

HyperLink1

ID

HyperLink1

 

Text

Visual Studio .NET

 

NavigateURL

ConstructionForm.aspx

 

BackColor

#FF80FF

continues

670

Project 5

CREATING A WEB PORTAL FOR A BOOKSTORE

 

 

 

 

 

 

Table 30-1 Properties for the Controls Added to the Main Form (continued)

 

 

 

 

 

 

 

 

Control

Property

Value

 

 

 

 

 

 

 

 

HyperLink2

ID

HyperLink2

 

 

 

 

 

Text

Operating Systems

 

 

 

 

 

NavigateURL

ConstructionForm.aspx

 

 

 

 

 

BackColor

#FF80FF

 

 

HyperLink3

ID

HyperLink3

 

 

 

 

 

Text

RDBMS

 

 

 

 

 

NavigateURL

ConstructionForm.aspx

 

 

 

 

 

BackColor

#FF80FF

 

 

HyperLink4

ID

HyperLink4

 

 

 

 

 

Text

Networking

 

 

 

 

 

NavigateURL

ConstructionForm.aspx

 

 

 

 

 

BackColor

#FF80FF

 

 

HyperLink5

ID

HyperLink5

 

 

 

 

 

Text

Internet

 

 

 

 

 

NavigateURL

ConstructionForm.aspx

 

 

 

 

 

BackColor

#FF80FF

 

 

Button

 

ID

btnGo

 

 

 

 

 

Text

Go

 

 

List

 

ID

lstType

 

 

 

 

 

Items

All

 

 

 

 

 

 

Author

 

 

 

 

 

 

Title

 

 

 

 

 

 

ISBN Number

 

 

 

 

 

 

Category

 

 

Table1

 

ID

Table1

 

 

 

 

 

BorderStyle

Outset

 

 

 

 

 

ForeColor

Purple

 

 

 

 

 

BackColor

#FF80FF

 

 

 

 

 

Rows

TableRow0

 

 

 

 

 

 

TableRow1

 

 

TableRow0

Cells

TableCell0

DEVELOPING WEB SERVICE CLIENTS

Chapter 30

671

 

 

 

 

Table 30-1 Properties for the Controls Added to the Main Form (continued)

Control

Property

Value

TableCell0

Text

Search

 

Font

Verdana, Small

 

ForeColor

Purple

 

VerticalAlign

Top

Table2

ID

Table2

 

BorderStyle

Outset

 

ForeColor

Purple

 

BackColor

Magenta

 

Rows

TableRow0

TableRow0

BorderStyle

Outset

 

BackColor

#FFC0FF

 

Cells

TableCell0

TableCell0

BackColor

#FF80FF

TextBox1

ID

txtSearch

 

 

 

After creating the form in the design view, the form looks as shown in Figure 30-1.

FIGURE 30-1 The Main form

672 Project 5 CREATING A WEB PORTAL FOR A BOOKSTORE

Creating the Results Form

The Results page is generated to display the results of the user’s query. To create the Results form, you need to include a DataGrid, a label, and a hyperlink control. You can name the Results form DispResultForm. After adding the controls, you need to change the properties of the Web form controls as shown in Table 30-2.

Table 30-2 Properties for the Controls Added to the Results Form

Control

Property

Value

HyperLink1

ID

HyperLink1

 

Text

Home

 

NavigateURL

MainForm.aspx

Lable1

ID

lblInfo

 

Font

Verdana, Large

 

ForeColor

#400040

DataGrid1

ID

DataGrid1

 

BackColor

#E0E0E0

 

 

 

After adding the DataGrid control to the form, you need to add button controls to the DataGrid control. To do this, perform the following steps:

1.Select the DataGrid control to view its Properties window.

Below the Properties window, the Property Builder link is displayed.

2.Click on the Property Builder link to display the DataGrid1 Properties dialog box.

3.In the DataGrid1 Properties dialog box, select the Columns tab in the left hand pane.

4.In the Available columns: list box, expand the Button Column node.

5.Select the Select option and click on the right arrow button to add the Select button.

When you add the Select button, the text boxes in the ButtonColumn properties area become enabled.

DEVELOPING WEB SERVICE CLIENTS

Chapter 30

673

 

 

 

 

6.In the Text: text box, type the text as Order.

7.In the Command name: text box, type the value as Ord.

8.In the Button Type: list box, select the value as LinkButton.

9.Click on the OK button to close the DataGrid1 Properties dialog box.

Figure 30-2 shows the DataGrid1 Properties dialog box.

FIGURE 30-2 The DataGrid1 Properties dialog box

When you create the form, the DispResultForm form looks as shown in Figure 30-3.

674 Project 5 CREATING A WEB PORTAL FOR A BOOKSTORE

FIGURE 30-3 The DispResultForm form

Creating the Orders Form

The Orders form stores the details of the book and the customers who order a book at the Web site. To do this, 1 button control, 2 hyperlink controls, 12 label controls, 1 list control, 5 RequiredFieldValidator controls, and 10 text box controls are added to the form. Name this Web form OrdersForm. In the OrdersForm form, change the properties of the controls as shown in Table 30-3.

Table 30-3 Properties for the Controls Added to the Orders Form

Control

Property

Value

Button1

ID

btnClear

 

Text

Clear

Button2

ID

btnOrder

 

Text

Order

HyperLink1

ID

HyperLink1

 

Text

Home

 

NavigateURL

MainForm.aspx

Label1

ID

Label1

 

Text

ISBN Number

 

ForeColor

Purple

DEVELOPING WEB SERVICE CLIENTS

Chapter 30

675

 

 

 

 

Table 30-3 Properties for the Controls Added to the Orders Form (continued)

Control

Property

Value

Label2

ID

Label2

 

Text

Enter your details here

 

ForeColor

Purple

 

Font

Monotype Corsiva, Large

Label3

ID

Label3

 

Text

Book Title

 

ForeColor

Purple

Label4

ID

Label4

 

Text

Name

 

ForeColor

Purple

Label5

ID

Label5

 

Text

Address1

 

ForeColor

Purple

Label6

ID

Label6

 

Text

Address2

 

ForeColor

Purple

Label7

ID

Label7

 

Text

City

 

ForeColor

Purple

Label8

ID

Label8

 

Text

State

 

ForeColor

Purple

Label9

ID

Label9

 

Text

Author

 

ForeColor

Purple

List

ID

lstCardType

 

Items

Amex

 

 

Visa

 

 

Master

Text Box1

ID

TextBox1

 

TextMode

Multiline

 

Enabled

False

 

Font

Verdana

676 Project 5 CREATING A WEB PORTAL FOR A BOOKSTORE

Table 30-3 Properties for the Controls Added to the Orders Form (continued)

Control

Property

Value

Text Box2

ID

txtAddr1

Text Box3

ID

txtAddr2

Text Box4

ID

txtAuthor

 

Enabled

False

Text Box5

ID

txtCardNumber

Text Box6

ID

txtCity

Text Box7

ID

txtISBN

 

Enabled

False

Text Box8

ID

txtName

Text Box9

ID

txtState

Text Box10

ID

txtTitle

RequiredFieldValidator1

ID

RequiredFieldValidator1

 

ControlToValidate

txtCardNumber

 

ErrorMessage

Please enter the Credit Card

 

 

Number

RequiredFieldValidator2

ID

RequiredFieldValidator3

 

ControlToValidate

txtName

 

ErrorMessage

Please enter your Name

 

Text

Please enter your Name

RequiredFieldValidator3

ID

RequiredFieldValidator4

 

ControlToValidate

txtCardNumber

 

ErrorMessage

Please enter your Name

 

Text

Please enter your Name

RequiredFieldValidator4

ID

RequiredFieldValidator5

 

ControlToValidate

txtAddr1

 

ErrorMessage

Please enter the Address

RequiredFieldValidator5

ID

RequiredFieldValidator6

 

ControlToValidate

txtCity

 

ErrorMessage

Please enter the City

DEVELOPING WEB SERVICE CLIENTS

Chapter 30

677

 

 

 

 

Table 30-3 Properties for the Controls Added to the Orders Form (continued)

Control

Property

Value

RequiredFieldValidator6

ID

RequiredFieldValidator7

 

ControlToValidate

txtState

 

ErrorMessage

Please enter the State

 

 

 

In addition to the previously mentioned controls, you need to add an sqlDataAdapter, an sqlConnection, and Dataset objects to the OrdersForm form. I have already explained the steps to include these controls to the form in Chapter 29, “Developing Web Services,” in the section “Creating a Web Service for Deepthoughts Publications.”

Figure 30-4 shows the form after it is created.

FIGURE 30-4 The OrdersForm form

Creating the Search Form

The Search form allows a user to search for records based on criteria. Therefore, the user needs to enter the criteria and a value for the criteria. To create the Search form, add a label control, two button controls, four radio buttons, and four text box controls to the form and then change the properties of the controls added to

678 Project 5 CREATING A WEB PORTAL FOR A BOOKSTORE

the form.The properties that you need to change in the Search page are specified in Table 30-4.

Table 30-4 Properties for the Controls Added to the Search Form

Control

Property

Value

Button1

Button2

Label1

Radio Button1

Radio Button2

Radio Button3

Radio Button4

Text Box1

Text Box2

Text Box3

Text Box4

ID

 

 

Y

ID

 

 

Text

 

 

 

ID

 

F

ID

 

Text

M

 

ForeColor

L

A

 

E

 

 

Text

 

 

 

GroupName

 

T

 

 

 

ForeColor

 

 

ID ext

GroupName ForeColor

ID

Text

GroupName

ForeColor

ID

Text

GroupName

ForeColor

ID

ID

ID

ID

btnHome Home

btnSearch Search

lblInfo Red

radAuthor Author Criteria #400040

radCategory Category Criteria #400040

radISBN ISBN Number Criteria #400040

radTitle Title Criteria #400040

txtAuthor

txtCategory

txtISBN

txtTitle

Figure 30-5 shows the Search form when it is created.

Team-Fly®

DEVELOPING WEB SERVICE CLIENTS

Chapter 30

679

 

 

 

 

FIGURE 30-5 The Search form

Once the form is created, you can rename the form SearchForm.

Creating the Construction Form

To create the construction form, add a hyperlink control and two label controls to the form. Rename the form ConstructionForm. Next, you need to change the properties of the controls, as shown in Table 30-5.

Table 30-5 Properties for the Controls Added to the Construction Form

Control

Property

Value

Label1

ID

Label1

 

Text

This page is under construction.

 

ForeColor

Purple

 

Font

Verdana, Large

Label2

ID

Label2

 

Text

Check out later...

 

ForeColor

Purple

 

Font

Verdana, Large

HyperLink1

ID

HyperLink1

 

Text

Home

 

NavigateURL

MainForm.aspx