In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to use VB.NET to call Web Service. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
The specific steps for VB.NET to call the Web Service service to write a database application:
1. Start Visual Studio .net.
two。 After selecting the menu [File] | [New] | [Project], the [New Project] dialog box pops up.
3. Set [Project Type] to [Visual Basic Project].
4. Set [template] to [Windows Application].
5. Enter [TestWebService] in the [name] text box.
6. Enter [E:\ VS.NET Project] in the text box of [location], and then click the [OK] button, so that a folder named "TestWebService" is created in the "E:\ VS.NET Project", which contains all the files of the TestWebService project.
7. Select [solution Explorer] | [reference], right-click, select "add Web reference" from the pop-up menu, enter "http://localhost/UpdateDataWebService/Service1.asmx" in the [address] text box in the pop-up "add Web reference" dialog box, click enter, and then add the Web reference to the [TestWebService] project. Please note that "http://localhost/UpdateDataWebService/Service1.asmx" is the URL address of the Web Service service provided above.
8. From the Windows forms components tab in the Toolbox, drag the following components into the Form1 form, and perform the appropriate actions:
A DataGrid component.
Two Button components, namely Button1 to Button2, and after the two Button components are dragged into the design form of Form1, double-click them respectively, and the system will generate the handling code corresponding to the Click events of these two components in the Form1.vb file.
9. Switch the current window of VB.NET to the code editing window of Form1.vb and replace the handling code corresponding to the Click event of Button1 in Form1.vb with the following code. The following code function is that VB.NET calls the "Binding" service provided in Web Service to implement data binding to 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
10. Replace the handling code for the Click event of Button2 in Form1.vb with the following code, which modifies database data through DataGrid using the "Update" service implementation provided in 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 Is Nothing) Then
Ds.Merge (MyService.Update (dsChanges), True)
End If
End Sub
11. At this point, all the work of the [TestWebService] project is done, and it is not easy for VB.NET to call WebService. Click the shortcut key F5 to run the program at this time. Clicking the "bind" button in the program will bind the data to the DataGrid components in the program, and clicking the "modify" button in the program will update the database according to the contents of the DataGrid.
12. The code listing of Form1.vb is as follows:
Public Class Form1
Inherits System.Windows.Forms.Form
# Region Code generated by the Windows forms designer
Public Sub New ()
MyBase.New ()
'This call is required by the Windows forms designer.
InitializeComponent ()
'add any initialization after the InitializeComponent () call
End Sub
'form rewrite disposal to clean up the list of components.
Protected Overloads Overrides Sub Dispose (ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
Components.Dispose ()
End If
End If
MyBase.Dispose (disposing)
End Sub
'required for the Windows forms designer
Private components As System.ComponentModel.IContainer
'Note: the following procedures are required for the Windows forms designer
'you can modify this process using the Windows forms designer.
'don 't use the code editor to modify it.
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
Private Sub InitializeComponent ()
Me.Button1 = New System.Windows.Forms.Button ()
Me.Button2 = New System.Windows.Forms.Button ()
Me.DataGrid1 = New System.Windows.Forms.DataGrid ()
CType (Me.DataGrid1, System.ComponentModel.ISupportInitialize) .BeginInit ()
Me.SuspendLayout ()
Me.Button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat
Me.Button1.Location = New System.Drawing.Point (56,216)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size (75,32)
Me.Button1.TabIndex = 0
Me.Button1.Text = "bind"
Me.Button2.FlatStyle = System.Windows.Forms.FlatStyle.Flat
Me.Button2.Location = New System.Drawing.Point (168,216)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size (75,32)
Me.Button2.TabIndex = 1
Me.Button2.Text = "modify"
Me.DataGrid1.DataMember = ""
Me.DataGrid1.Dock = System.Windows.Forms.DockStyle.Top
Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.DataGrid1.Name = "DataGrid1"
Me.DataGrid1.Size = New System.Drawing.Size (292,192)
Me.DataGrid1.TabIndex = 2
Me.AutoScaleBaseSize = New System.Drawing.Size (6,14)
Me.ClientSize = New System.Drawing.Size (292,273)
Me.Controls.AddRange (New System.Windows.Forms.Control () {Me.DataGrid1, Me.Button2, Me.Button1})
Me.Name = "Form1"
Me.Text = "Test Web Service"
CType (Me.DataGrid1, System.ComponentModel.ISupportInitialize) .EndInit ()
Me.ResumeLayout (False)
End Sub
# End Region
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
End Class
This is the end of the article on "how VB.NET calls Web Service". I hope the above content can be helpful to you so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.