Consume XML Web Services
Số trang: 5
Loại file: pdf
Dung lượng: 17.46 KB
Lượt xem: 6
Lượt tải: 0
Xem trước 2 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Tiêu thụ 13,3 XML Web Services tôi đã tạo ra dịch vụ này web mà có các tên người dùng và mật khẩu và trả về True hay False dựa vào việc tên người dùng và mật khẩu kiểm tra. Tôi đã thậm chí đã thử nghiệm dịch vụ Web để đảm bảo rằng nó hoạt động chính xác.
Nội dung trích xuất từ tài liệu:
Consume XML Web Services 13.3 Consume XML Web ServicesI have created this Web Service that takes the username and password and returns True orFalse based on whether the username and password check out. I have even tested theWeb Service to make sure it works correctly. How do I use, or consume, this WebService in another application?TechniqueTo use a Web Service, you need to create a reference to it.Setting Up the Web Reference to the Web ServiceTo set up a Web reference, you choose Add Web Reference from the Project menu. Youare then presented with the Add Web Reference dialog box, which allows you to browsefor Web Services using the Universal Description Discovery Integration (UDDI)directories, as described in the beginning of the chapter. However, you will be able tobrowse to the Web Service you created and supply the name of the full URL usinglocalhost to the name of the .asmx file you created, in this case:http://localhost/securitywebservice/SecurityServices.asmxAfter you have specified this, you will see the methods appear for your Web Service (seeFigure 13.11.) Figure 13.11. You can test the Web Service right in this dialog box.Note You can see two methods for this Web Service: TestUserPassword and GetUserInfo. The second method is discussed in How-To 13.4.After you have clicked Add Reference to accept the new reference, you can use themethods in your application. You can double-check that the reference is there by lookingfor it under the Web Reference node that appears in the Solution Explorer (see Figure13.12.) Figure 13.12. You can see the reference created in the Solution Explorer.Calling Web Service MethodsAfter you have created the reference to the Web Service, you will create a referencewithin your application, much like you would to other object models. Following is asnippet of code that performs this very task:Dim wsSec As localhost.SecurityServiceswsSec = New localhost.SecurityServices()If wsSec.TestUserPassword(Me.txtUser.Text, Me.txtPassword.Text) ThenAs you can see, the method TestUserPassword is called just as another other method orfunction is called.StepsTo preview this How-To, open the solution called Visual Basic .NET-Chapter 13, locatedin the chapter folder.Note You will probably have to re-establish the Web reference for the Web Service that is used for this example. Locate where you have installed SecurityWebServices and set the reference.When you run the project, the first form that comes up is the main switchboard with eachof the How-Tos listed for this chapter. Click on How-To 13.3. The form for How-To 13.3opens.If you type FSBarker for the User and Test for the Password, you get a message boxtelling you that you can continue into the application (see Figure 13.13). 1. Create a new Visual Studio .NET project using the Windows Application project template. Create a Windows Form, and place the controls shown in Table 13.1 in the order displayed in Figure 13.13. Table 13.1. Label, TextBox, and Command Button Control Property Settings Object Property Setting Label Text User TextBox Name txtUser Label Text Password TextBox Name txtPassword Button Name btnLogin 2. As described in the Technique section, set a reference to the Web Service you created in the previous How-To. Remember to point to the *.asmx file created in the Web Service. Choose Add Web Reference from the Project menu. 3. Add the code listed in Listing 13.3 to the Click event of btnLogin by double- clicking on the button. This routine instantiates an instance of the Web Service. Then, using the wsSec object, the routine calls the TestUserPassword method. This method is passed the username and password that were entered. Listing 13.3 frmHowTo13_3.vb: Web Method to Validate Username and Password Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click Dim wsSec As localhost.SecurityServices wsSec = New localhost.SecurityServices() If wsSec.TestUserPassword(Me.txtUser.Text, Me.txtPassword.Text) Then MessageBox.Show(You may go into the applcation.) Else MessageBox.Show(You may not go into the application.) End If End Sub Figure 13.13. This login form takes advantage of a Web Service for authentication.CommentNote that passing parameters and using the return value is just like using methods fromother objects or even functions from your o ...
Nội dung trích xuất từ tài liệu:
Consume XML Web Services 13.3 Consume XML Web ServicesI have created this Web Service that takes the username and password and returns True orFalse based on whether the username and password check out. I have even tested theWeb Service to make sure it works correctly. How do I use, or consume, this WebService in another application?TechniqueTo use a Web Service, you need to create a reference to it.Setting Up the Web Reference to the Web ServiceTo set up a Web reference, you choose Add Web Reference from the Project menu. Youare then presented with the Add Web Reference dialog box, which allows you to browsefor Web Services using the Universal Description Discovery Integration (UDDI)directories, as described in the beginning of the chapter. However, you will be able tobrowse to the Web Service you created and supply the name of the full URL usinglocalhost to the name of the .asmx file you created, in this case:http://localhost/securitywebservice/SecurityServices.asmxAfter you have specified this, you will see the methods appear for your Web Service (seeFigure 13.11.) Figure 13.11. You can test the Web Service right in this dialog box.Note You can see two methods for this Web Service: TestUserPassword and GetUserInfo. The second method is discussed in How-To 13.4.After you have clicked Add Reference to accept the new reference, you can use themethods in your application. You can double-check that the reference is there by lookingfor it under the Web Reference node that appears in the Solution Explorer (see Figure13.12.) Figure 13.12. You can see the reference created in the Solution Explorer.Calling Web Service MethodsAfter you have created the reference to the Web Service, you will create a referencewithin your application, much like you would to other object models. Following is asnippet of code that performs this very task:Dim wsSec As localhost.SecurityServiceswsSec = New localhost.SecurityServices()If wsSec.TestUserPassword(Me.txtUser.Text, Me.txtPassword.Text) ThenAs you can see, the method TestUserPassword is called just as another other method orfunction is called.StepsTo preview this How-To, open the solution called Visual Basic .NET-Chapter 13, locatedin the chapter folder.Note You will probably have to re-establish the Web reference for the Web Service that is used for this example. Locate where you have installed SecurityWebServices and set the reference.When you run the project, the first form that comes up is the main switchboard with eachof the How-Tos listed for this chapter. Click on How-To 13.3. The form for How-To 13.3opens.If you type FSBarker for the User and Test for the Password, you get a message boxtelling you that you can continue into the application (see Figure 13.13). 1. Create a new Visual Studio .NET project using the Windows Application project template. Create a Windows Form, and place the controls shown in Table 13.1 in the order displayed in Figure 13.13. Table 13.1. Label, TextBox, and Command Button Control Property Settings Object Property Setting Label Text User TextBox Name txtUser Label Text Password TextBox Name txtPassword Button Name btnLogin 2. As described in the Technique section, set a reference to the Web Service you created in the previous How-To. Remember to point to the *.asmx file created in the Web Service. Choose Add Web Reference from the Project menu. 3. Add the code listed in Listing 13.3 to the Click event of btnLogin by double- clicking on the button. This routine instantiates an instance of the Web Service. Then, using the wsSec object, the routine calls the TestUserPassword method. This method is passed the username and password that were entered. Listing 13.3 frmHowTo13_3.vb: Web Method to Validate Username and Password Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click Dim wsSec As localhost.SecurityServices wsSec = New localhost.SecurityServices() If wsSec.TestUserPassword(Me.txtUser.Text, Me.txtPassword.Text) Then MessageBox.Show(You may go into the applcation.) Else MessageBox.Show(You may not go into the application.) End If End Sub Figure 13.13. This login form takes advantage of a Web Service for authentication.CommentNote that passing parameters and using the return value is just like using methods fromother objects or even functions from your o ...
Tìm kiếm theo từ khóa liên quan:
công nghệ máy tính phần mềm kỹ thuật lập trình lập trình dữ liệu Consume XMLGợi ý tài liệu liên quan:
-
Kỹ thuật lập trình trên Visual Basic 2005
148 trang 245 0 0 -
NGÂN HÀNG CÂU HỎI TRẮC NGHIỆM THIẾT KẾ WEB
8 trang 179 0 0 -
Giới thiệu môn học Ngôn ngữ lập trình C++
5 trang 177 0 0 -
6 trang 170 0 0
-
Luận văn: Nghiên cứu kỹ thuật giấu tin trong ảnh Gif
33 trang 147 0 0 -
Bài giảng Nhập môn về lập trình - Chương 1: Giới thiệu về máy tính và lập trình
30 trang 143 0 0 -
Báo cáo thực tập Công nghệ thông tin: Lập trình game trên Unity
27 trang 113 0 0 -
Giáo trình về phân tích thiết kế hệ thống thông tin
113 trang 112 0 0 -
LUẬN VĂN: Tìm hiểu kỹ thuật tạo bóng cứng trong đồ họa 3D
41 trang 104 0 0 -
Bài giảng Kỹ thuật lập trình - Chương 10: Tổng kết môn học (Trường Đại học Bách khoa Hà Nội)
67 trang 102 0 0