Vb.net,c#.net invoking Web Service, leveraging Visual Studio's implementation approach

Source: Internet
Author: User

Invoking the service provided by the Web service in vb.net

Technical QQ Exchange Group: javadream:251572072

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

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

When a Web service is already in service state, VB. NET can use these services through HTTP "invoke". Of course, the premise is to understand the Web service to provide services for the URL, when the Web service to understand the corresponding URL, VB. NET is like using the various features available in the Web service as if it were a local class library. So some people say that Web service is essentially a way of invoking remote components over HTTP. You can see step seventh in the following steps in the vb.net implementation to join a Web service.

The database application described below uses the" binding "service provided in the Web service above to implement data binding to the DataGrid component in the program, providing the use of the" Update Service to modify the database through the DataGrid in the program. Here's how vb.net calls the Web service provider to write a database application:
1. Start visual Studio. Net.
2. After you select the menu file | new | project, the new Project dialog box pops up.
3. Set the project type to Visual basic project.
4. Set the template to Windows application.
5. Enter "TestWebService" in the "Name" text box.
6. In the text box for location, enter E:\VS. NET project, and then click the OK button, so in the E:\VS. NET project "creates a folder called" TestWebService ", which contains all the files of the TestWebService project.
7. After you select Solution Explorer | references, right-click to select Add Web Reference from the pop-up menu, enter "in the Address text box in the Add Web Reference dialog box that pops up, and then click Enter to see the interface shown in Figure 03. Click the Add Reference button in Figure 03 to include a Web reference in the TestWebService project. Please note that "" is the URL address of the Web service that was completed above to provide services externally.
8. From the Windows Forms Components tab in the Toolbox, drag the following components into the Form1 form and take the appropriate action:
DataGrid component.
button components, respectively Button1 through Button2, and double-clicking them after the two button components are dragged into the Form1 design form, the system will produce the processing code corresponding to the click event for the two components in the Form1.vb file respectively.

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

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

 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   

At this point, the full work of the "TestWebService" project is complete, and invoking the Web service is not easy. Now click the shortcut key F5 after you run the program. Clicking the Bind button in the program implements data binding on the DataGrid component in the program, clicking the Modify button in the program, and the program updates the database based on the contents of the DataGrid.

Vb.net,c#.net invoking Web Service, leveraging Visual Studio's implementation approach

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.