This step-by-step article describes how to access a Web
service in a Microsoft Windows-based application by using Microsoft Visual Basic 2005 or Microsoft Visual Basic
.NET.
Add the Web service
reference to the Windows-based application
You can add a reference to a Web service by using Visual Studio, or you can generate the proxy for the Web service by using the Wsdl.exe tool (WSDL), and
then by using that proxy to access the Web service in your Windows-based application.
By using Visual Studio
In Solution Explorer, right-click ServiceConsumer, and
then click Add Web Reference.
The Add Web
Reference dialog box appears.
In the Address bar, type the TestWebService URL, and then press ENTER. For example, if
TestWebService is located in the root directory of a Web server, type the
following
address:
http://WebServerName/TestWebService/Service1.asmx
After TestWebService is located, click Add
Reference.
In Solution Explorer, right-click Form1, and then click
View Code.
Add the following namespace at the top of the
Form1.vb file.
Imports ServiceConsumer.<WebReferenceName>
Note <WebReferenceName> is the name of the Web reference as it appears
under Web References in Solution Explorer.
By using the WSDL Tool
Open a Command Prompt window in Visual Studio.
Change the folder to the location
where you created the ServiceConsumer application.
Consume the Web service
in the Windows-based application
In Solution Explorer, right-click Form1, and then click
View Code.
Add the following code to Form1.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Create an instance of the Web service.
Dim myService As New Service1()
' Consume the Web Service method.
MessageBox.Show(myService.HelloWorld())
End Sub
On the Debug menu, click
Start to run the application.