VB. NET, C #. NET calls Web Service and uses the implementation method of visual studio,

Source: Internet
Author: User

VB. NET, C #. NET calls Web Service and uses the implementation method of visual studio,

Call the services provided by Web Service in VB. NET

Technology qq exchange group: JavaDream: 251572072

The following is a detailed article. In fact, the specific operation is very simple. Add the Web Service address and the tool (VS2010) to the project by adding references.

If you do not know the playground in this place, you can ask me QQ: 1606841559  

When the Web Service is already providing external services, VB. NET can use these services through HTTP "call. Of course, the premise is to understand the URL of the Web Service to provide external services. After learning about the URL of the Web Service, VB. NET is like using a local class library to use various functions provided by Web Service. Therefore, some people say that Web services are essentially a way to call Remote components over HTTP. For more information about how to add Web services to VB. NET, see Step 7 in the following steps.

The database application described below is to bind data to the DataGrid component in the program by using the "Binding" Service provided in the Web Service above, you can use the "Update" Service provided in Web Service to modify the database through the DataGrid in the program. The following describes how to compile a database application by using VB. NET to call the Web Service:
1. Start Visual Studio. Net.
2. Select File, new, and project. The new project dialog box is displayed.
3. Set project type to Visual Basic Project ].
4. Set template to Windows application ].
5. Enter TestWebService In the Name text box ].
6. in the location text box, enter E: \.. NET project, and then click OK. the "TestWebService" folder is generated in the "NET project", which stores all files of the TestWebService project.
7. select Solution Explorer | reference, right-click, and choose add Web reference from the shortcut menu ], in the Add Web reference dialog box that appears, enter "" in the address text box and click Enter. The page shown in Figure 03 is displayed. Click Add reference in Figure 03 to add a Web reference to the TestWebService project. Note that "" is the URL address of the Web Service provided to external users.
8. Drag the following components to Form1 form from the Windows Forms components tab in the toolbox and perform the corresponding operations:
◆ DataGrid component.
◆ Button components: Button1 to Button2, drag the design form of Form1 into the buttons, and double-click them, respectively, the system generates the processing code corresponding to the Click events of the two components in the Form1.vb file.

Set VB. the current window of NET switches to the code editing window of Form1.vb, and replaces the processing code corresponding to the Click event of Button1 in Form1.vb with the following code, the following code functions bind data to the DataGrid component using the "Binding" Service provided by Web Service:

    Private Sub Button1_Click (     ByVal sender As System.Object , ByVal e As System.EventArgs )     Handles Button1.Click    Dim MyService As New localhost.Service1 ( )    DataGrid1.DataSource = MyService.Binding ( )    DataGrid1.DataMember = "Cust"   End Sub  

Use the following code to replace the processing code corresponding to the Click event of Button2 in Form1.vb. The following code function is to use the "Update" Service provided by Web Service to modify database data through the DataGrid:

    Private Sub Button2_Click (    ByVal sender As System.Object , ByVal e As System.EventArgs )     Handles Button2.Click    Dim MyService As New localhost.Service1 ( )    Dim ds As DataSet = DataGrid1.DataSource    Dim dsChanges As DataSet = ds.GetChanges ( )    If Not ( dsChanges Is Nothing ) Then    ds.Merge ( MyService.Update ( dsChanges ) , True )    End If    End Sub  

So far, all the work of the TestWebService project has been completed. It is very easy to call the Web Service. Click the shortcut key F5 to run the program. Click the "bind" button in the program to bind data to the DataGrid component in the program. Click the "modify" button in the program to update the database according to the content in the DataGrid.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.