Vb.net,c#.net calls the Web Service, using Visual Studio implementation methods __.net

Source: Internet
Author: User

invoke the service provided by the Web service at vb.net

Technology QQ Exchange Group: javadream:251572072

The following is an article more detailed, in fact, the specific operation is very simple, the Web service address, the use of tools (VS2010), by adding a reference to the form, add to the project can be applied.

If this place doesn't have a playground, you can ask me qq:1606841559  

When the Web service is already in the service state of the external provider, VB. NET can use these services through HTTP "invoke". Of course, the premise is to understand the Web service to provide services to the corresponding URL, when the Web service to understand the corresponding URL, VB. NET is like using a local class library to use the various features provided in the Web service. So some people say that Web service is essentially a way of calling remote components over HTTP. Adding a Web service to the vb.net implementation can be found in step seventh of the following steps.

The database application described below implements data binding to the DataGrid component in the program by using the "Binding" service provided in the above Web service, providing the "Update" service provided in the Web service. Modify the database by using a DataGrid in the program. Here's how vb.net calls the Web service to provide services to write database applications:
1. Start visual Studio. Net.
2. Select Menu "File" | "new" | "Project", Pop-up the New Project dialog box.
3. Set the project type to Visual basic project.
4. Set "template" to "Windows Application".
5. Enter "TestWebService" in the Name text box.
6. Enter the E:\VS in the text box in the location. NET project, and then click the OK button, so that in the E:\VS. NET project "is called" TestWebService "folder, which is stored in the TestWebService project all the files.
7. After you select Solution Explorer | "References", click the right mouse button, select "Add Web Reference" in the pop-up menu, and after entering "in the Address" text box in the pop-up Add Web Reference dialog box, click the ENTER key to get the interface shown in Figure 03. Click the Add Reference button in Figure 03 to include a Web reference in the TestWebService project. Note that "" is the URL address for the service provided by the Web service completed above.
8. From the Windows Forms Components tab in the Toolbox, drag the following components into the Form1 form and perform the appropriate actions:
the DataGrid component.
button component, which is Button1 to Button2, and when these two button components are dragged into the Form1 design form and double-click them respectively, the system will generate the processing code for the click events of the two components in the Form1.vb file, respectively.

Switch the current window of the vb.net to the Form1.vb Code editing window and replace the processing code for the Button1 click event in Form1.vb with the following code that uses the "Binding" provided in the Web service The service implements data binding to the DataGrid component:

  
Private Sub button1_click (
ByVal sender as System.Object, ByVal e as System.EventArgs)
Handles Button 1.Click
Dim myservice as New localhost. Service1 ()
DataGrid1.DataSource = myservice.binding ()
DataGrid1.DataMember = "Cust" End
Sub

Replace the processing code for the Button2 click event in Form1.vb with the following code to modify the database data through the DataGrid using the "Update" service provided in the Web service:

  
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 are nothing) Then
ds. Merge (Myservice.update (dschanges), True) end
If End
Sub

At this point, all the work on the "TestWebService" project is complete, and it is not easy to invoke the Web service. Click the shortcut key F5 after running the program. Clicking the Bind button in the program implements data binding to the DataGrid component in the program, and clicking the Modify button in the program updates the database according to the contents of the DataGrid.

Related Article

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.