Web services technology is based on HTTP, Simple Object Access Protocol (SOAP), and XML. Since Web services use open standards, calling Web services is fairly simple.

VB.NET allows you to use Web services as if they were entirely local objects since most of the marshaling between the client and the server is taking place in the background. This tip shows you how to create a simple Web service.

Example

I will create a Web service and add a Web function that will return the current machine’s IP address. Here are the steps for creating a Web service:

  1. Open Visual Studio.Net and select Create New Website under VB.NET.
  2. Select Web Service from the options listed.
  3. Once you get the code window open, add the following code:
<WebMethod()> _

       Public Function GetMachineIPAddress() As String

        Dim strHostName As String = ""

        Dim strIPAddress As String = ""

        Dim host As System.Net.IPHostEntry

        strHostName = System.Net.Dns.GetHostName()

        strIPAddress = System.Net.Dns.GetHostEntry(strHostName).HostName.ToString()

        host = System.Net.Dns.GetHostEntry(strHostName)

        Dim ip As System.Net.IPAddress

        For Each ip In host.AddressList

            Return ip.ToString()

        Next

        Return ""

    End Function

Once you debug the example, you will see a screen that looks like Figure A.
Figure A

It will list two available Web methods: the one that was generated (HelloWorld) and the one I created (GetMachineIPAddress). Click the link for GetMachineIPAddress, and you will see a screen allowing you to get more information about this method and invoking it (Figure B).
Figure B

Click the Invoke button, and the result will look like Figure C.
Figure C

TechRepublic resources about Web services

Web services creation and usage represents a step in the direction of open standards. The myriad details about Web services are beyond the scope of this article. For more about Web services, check out these TechRepublic resources:

Irina Medvinskaya has been involved in technology since 1996. She has an MBA from Pace University and works as a project manager at Citigroup.

—————————————————————————————-

Get Visual Basic tips in your inbox

Advance your scripting skills to the next level with TechRepublic’s free Visual Basic newsletter, delivered each Friday. Automatically subscribe today!

Subscribe to the Project Management Insider Newsletter

Subscribe to Project Management Insider for best practices, reviews and resources. From project scheduling software to project planning apps, stay up to date with the latest in project management tools. Delivered Wednesdays

Subscribe to the Project Management Insider Newsletter

Subscribe to Project Management Insider for best practices, reviews and resources. From project scheduling software to project planning apps, stay up to date with the latest in project management tools. Delivered Wednesdays