Create a Simple XML Web Service Using Parameters
Thông tin tài liệu:
Nội dung trích xuất từ tài liệu:
Create a Simple XML Web Service Using Parameters 13.2 Create a Simple XML Web Service Using ParametersI have seen how to create a Web Service using the sample that Microsoft provides. Thiswas instructive but not very useful. How do I create a Web Service that uses parameters?TechniqueFor this How-To, you are going to create the start of a security Web Service. Thissecurity Web Service is going to take in two parameters: Login Name and Password. Itwill then check against a table that you will create of names, passwords, and securitylevels.The method you will create first will then pass back True or False if the name andpassword are found.Looking at the Security TableThe security table is included in the Web Services Web folder. It is calledWebServiceSecurity.MDB and is, in fact, a jet database. You can see the table created,tblUsers, in Figure 13.8. Figure 13.8. Using the tblUsers, you can look up usernames and passwordsThe method created for this first real example will take in the username and passwordand then look up the username. If the username is found, the method will then comparethe password. If the password matches, then True will be returned from the method.Otherwise, False will be returned.Passing ParametersYou will pass parameters to Web Service methods just as you would to any othermethods or functions, as shown in the function header for the Web Service methodcreated in this How-To:Public Function TestUser(ByVal strUserID As String, ByVal strPassword As String) As BooleanThe return value is also assigned to the name of the function.Specifying Descriptions for the Web Service and MethodsYou can help developers who use your Web Service by adding descriptions to the WebService and each of the methods you create. This cuts down on the number of supportrequests you get, and is a good habit to get into. For the Web Service, you will place it inthe WebService header, where you will want to specify your own namespace as well: _ Public Class SecurityServices_This causes the description specified to be displayed as the first line on the main testpage.For the method, you will include the description in the Web Method header: Public Function TestUserPassword(ByVal strUserID As String, _ ByVal strPassWord As String) As BooleanYou can see what the lines of code look like in the designer in Figure 13.9. Figure 13.9. Adding descriptions to the Web Service.Now its time to put it all together.StepsOpen and run the SecurityWebService solution. From the main test page, click on the linkfor the method TestUserPassword. You are presented with a page to input the user ID andpassword (see Figure 13.10.) If you type FSBarker for the strUserID and test for thestrPassword, the value True is returned; otherwise, False is returned. 1. Create an ASP.NET Web service project, calling it SecurityWebService. 2. Highlight the default .asmx file created in the Solution Explorer, renaming it to SecurityServices.asmx. 3. Click on the View Code button in the Solution Explorer. Change the WebService at the top of the code to read as follows: 4. _ 6. Public Class SecurityServices 7. Add the code in Listing 13.2 to the code of the Web Service. (Double-click on the Web Service to bring up the code.) You could replace the commented out lines that display for the Hello World Web method. This code starts off by specifying the description for the Web Method and then declaring the function header for the method called TestUserPassword. The parameters strUserID and strPassword are passed, and a Boolean type value is returned. The rest of this routine should looksomewhat familiar because a DataAdapter object is created, and a DataTableobject is filled, based on the username that was passed in.If a record is not found for the user, then False is passed back.If a record is found and the password matches, then True is passed back. If thepassword for the user does not match, then False is passed back.Listing 13.2 SecurityServices.asmx.vb: Web Method to Validate Usernameand PasswordPublic Function TestUserPassword(ByVal strUserID As String, _ ByVal strPassword As String) As Boolean Dim ocnn As New _ OleDb.OleDbConnection(Provider=Microsoft.Jet.OLEDB.4.0; & _ Data Source=E:InetPubwwwrootSecurityWebService & _ WebServiceSecurity.MDB) Dim odaUsers As New _ OleDb.OleDbDataAdapter(Select * from tblUsers & _Where UserID = &strUserID & , ocnn) Dim dtUsers As New DataTable() odaUsers.Fill(dtUsers) If dtUsers.Rows.Count = 0 Then TestUserPassword = False ElseIf dtUsers.Rows(0).Item(Password) = strPassword Then TestUserPassword = True Else TestUserPassword = False End IfEnd FunctionNo ...
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 Create a Simple XMLTài liệu liên quan:
-
Kỹ thuật lập trình trên Visual Basic 2005
148 trang 266 0 0 -
NGÂN HÀNG CÂU HỎI TRẮC NGHIỆM THIẾT KẾ WEB
8 trang 208 0 0 -
Giới thiệu môn học Ngôn ngữ lập trình C++
5 trang 195 0 0 -
6 trang 192 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 169 0 0 -
Luận văn: Nghiên cứu kỹ thuật giấu tin trong ảnh Gif
33 trang 153 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 119 0 0 -
Giáo trình về phân tích thiết kế hệ thống thông tin
113 trang 114 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 109 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 106 0 0 -
Giáo trình Lập trình Web với Servlet và JSP: Phần 1
56 trang 96 0 0 -
Giáo trình Nhập môn lập trình VB6: Phần 2
184 trang 93 0 0 -
Giáo trình Nhập môn lập trình VB6: Phần 1
246 trang 85 0 0 -
Giáo trình toán rời rạc - Phụ lục 2
15 trang 85 0 0 -
Nghiên cứu triển khai nội địa hóa máy tính thương hiệu Việt Nam
585 trang 83 0 0 -
Giáo trình Lập trình hướng đối tượng với Java: Phần 2 - Trần Thị Minh Châu, Nguyễn Việt Hà
141 trang 75 0 0 -
Cách chia sẻ File, dữ liệu mạng Lan trong Windows Xp
10 trang 61 0 0 -
Giáo trình Ngôn ngữ lập trình C++: Phần 2 - TS. Vũ Việt Vũ
107 trang 58 0 0 -
Luận văn: TÌM HIỂU KỸ THUẬT LẬP TRÌNH NETWORK SERVICE CHO WINDOW
39 trang 55 0 0 -
Bài giảng Kỹ thuật lập trình: Chương 7 - Trần Quang
28 trang 52 0 0