Using a Web Service
Số trang: 3
Loại file: pdf
Dung lượng: 33.48 KB
Lượt xem: 10
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:
Thiết lập thuộc tính Name của DataGrid của bạn để customersDataGrid. Thiết lập thuộc tính Name của TextBox của bạn để whereClauseTextBox, và loại bỏ các văn bản textBox1 từ các tài sản văn bản. Thiết lập thuộc tính Name của Button của bạn để getCustomersButton, và thiết lập thuộc tính Text để Nhận Khách hàng. Những điều khiển được thể hiện trong hình
Nội dung trích xuất từ tài liệu:
Using a Web ServiceUsing a Web ServiceIn this section, youll see how to use a Web service in a Windows application.Start VS .NET and select File ➣ New ➣ Project. Create a new Windows applicationnamed UseWebServiceInWindows. Drag a DataGrid, TextBox, and Button control toyour form. Set the Name property of your DataGrid to customersDataGrid. Set the Nameproperty of your TextBox to whereClauseTextBox, and remove the text textBox1 fromthe Text property. Set the Name property of your Button to getCustomersButton, and setthe Text property to Get Customers. These controls are shown in Figure 17.7.Figure 17.7: Form with controlsOpen the Solution Explorer window and right-click the References node. Select AddWeb References from the pop-up menu. This displays the Add Web Reference dialogbox, which allows you to search for Web services. Enter the following URL in theAddress box, and press the Enter key on your keyboard:http://localhost/NorthwindWebService/Customers.asmxNote If your Web service is not deployed on the local computer, then replace localhost with the name of your remote computer.Your Web service will be located and a test page displayed (see Figure 17.8).Figure 17.8: Northwind Web ServiceYou can view the WSDL file for your Web service by clicking the Service Descriptionlink, and you can test your Web service by clicking the Retrieve Customers link.Click the Add Reference button to add the reference to your Web service to your projectand continue. You can see the new reference in the Solution Explorer window (see Figure17.9).Figure 17.9: The new Web reference in Solution ExplorerDouble-click the Button on your form to open the code editor, and add the following codeto your buttons click method:localhost.Customers myCustomersService = new localhost.Customers();customersDataGrid.DataSource = myCustomersService.RetrieveCustomers(whereClauseTextBox.Text);customersDataGrid.DataMember = Customers;Note Once again, if your Web service is not deployed on the local computer, then replace localhost in this code with the name of your remote computer.This code creates an object named myCustomersService to call your Web service, anddisplays the returned results from the RetrieveCustomers() method in customersDataGrid.Compile and run your Windows application by selecting Debug ➣ Start WithoutDebugging. Enter CustomerID=ALFKI in the text box, and click the Get Customersbutton; the retrieved results are shown in Figure 17.10.Figure 17.10: The running formNext, youll see how to register your Web service.
Nội dung trích xuất từ tài liệu:
Using a Web ServiceUsing a Web ServiceIn this section, youll see how to use a Web service in a Windows application.Start VS .NET and select File ➣ New ➣ Project. Create a new Windows applicationnamed UseWebServiceInWindows. Drag a DataGrid, TextBox, and Button control toyour form. Set the Name property of your DataGrid to customersDataGrid. Set the Nameproperty of your TextBox to whereClauseTextBox, and remove the text textBox1 fromthe Text property. Set the Name property of your Button to getCustomersButton, and setthe Text property to Get Customers. These controls are shown in Figure 17.7.Figure 17.7: Form with controlsOpen the Solution Explorer window and right-click the References node. Select AddWeb References from the pop-up menu. This displays the Add Web Reference dialogbox, which allows you to search for Web services. Enter the following URL in theAddress box, and press the Enter key on your keyboard:http://localhost/NorthwindWebService/Customers.asmxNote If your Web service is not deployed on the local computer, then replace localhost with the name of your remote computer.Your Web service will be located and a test page displayed (see Figure 17.8).Figure 17.8: Northwind Web ServiceYou can view the WSDL file for your Web service by clicking the Service Descriptionlink, and you can test your Web service by clicking the Retrieve Customers link.Click the Add Reference button to add the reference to your Web service to your projectand continue. You can see the new reference in the Solution Explorer window (see Figure17.9).Figure 17.9: The new Web reference in Solution ExplorerDouble-click the Button on your form to open the code editor, and add the following codeto your buttons click method:localhost.Customers myCustomersService = new localhost.Customers();customersDataGrid.DataSource = myCustomersService.RetrieveCustomers(whereClauseTextBox.Text);customersDataGrid.DataMember = Customers;Note Once again, if your Web service is not deployed on the local computer, then replace localhost in this code with the name of your remote computer.This code creates an object named myCustomersService to call your Web service, anddisplays the returned results from the RetrieveCustomers() method in customersDataGrid.Compile and run your Windows application by selecting Debug ➣ Start WithoutDebugging. Enter CustomerID=ALFKI in the text box, and click the Get Customersbutton; the retrieved results are shown in Figure 17.10.Figure 17.10: The running formNext, youll see how to register your Web service.
Tìm kiếm theo từ khóa liên quan:
máy tính mạng máy tính internet phần mềm ứng dụng lập trình SQL HTML sever web XMLGợi ý tài liệu liên quan:
-
Giáo án Tin học lớp 9 (Trọn bộ cả năm)
149 trang 263 0 0 -
Ngân hàng câu hỏi trắc nghiệm môn mạng máy tính
99 trang 251 1 0 -
Giáo trình Hệ thống mạng máy tính CCNA (Tập 4): Phần 2
102 trang 244 0 0 -
Bài giảng: Lịch sử phát triển hệ thống mạng
118 trang 244 0 0 -
47 trang 237 3 0
-
Đề cương chi tiết học phần Thiết kế và cài đặt mạng
3 trang 234 0 0 -
80 trang 216 0 0
-
122 trang 212 0 0
-
Giáo trình Hệ thống mạng máy tính CCNA (Tập 4): Phần 1
122 trang 210 0 0 -
Giáo trình môn học/mô đun: Mạng máy tính (Ngành/nghề: Quản trị mạng máy tính) - Phần 1
68 trang 201 0 0