Using a Web Service

Chia sẻ: Qweqwdasd Qweqdasda | Ngày: | Loại File: PDF | Số trang:3

0
36
lượt xem
5
download

Using a Web Service

Mô tả tài liệu
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

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

Chủ đề:
Lưu

Nội dung Text: Using a Web Service

  1. Using a Web Service In this section, you'll see how to use a Web service in a Windows application. Start VS .NET and select File ➣ New ➣ Project. Create a new Windows application named UseWebServiceInWindows. Drag a DataGrid, TextBox, and Button control to your form. Set the Name property of your DataGrid to customersDataGrid. Set the Name property of your TextBox to whereClauseTextBox, and remove the text textBox1 from the Text property. Set the Name property of your Button to getCustomersButton, and set the Text property to Get Customers. These controls are shown in Figure 17.7. Figure 17.7: Form with controls Open the Solution Explorer window and right-click the References node. Select Add Web References from the pop-up menu. This displays the Add Web Reference dialog box, which allows you to search for Web services. Enter the following URL in the Address box, and press the Enter key on your keyboard: http://localhost/NorthwindWebService/Customers.asmx Note 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).
  2. Figure 17.8: Northwind Web Service You can view the WSDL file for your Web service by clicking the Service Description link, 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 project and continue. You can see the new reference in the Solution Explorer window (see Figure 17.9). Figure 17.9: The new Web reference in Solution Explorer Double-click the Button on your form to open the code editor, and add the following code to your button's click method: localhost.Customers myCustomersService = new localhost.Customers(); customersDataGrid.DataSource = myCustomersService.RetrieveCustomers(whereClauseTextBox.Text); customersDataGrid.DataMember = "Customers";
  3. 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, and displays the returned results from the RetrieveCustomers() method in customersDataGrid. Compile and run your Windows application by selecting Debug ➣ Start Without Debugging. Enter CustomerID='ALFKI' in the text box, and click the Get Customers button; the retrieved results are shown in Figure 17.10. Figure 17.10: The running form Next, you'll see how to register your Web service.
Đồng bộ tài khoản