Creating a VB.NET Web Service in VS 2010






I was given the task of creating a program to communicate with a web service provided by VideoNext Network Solutions, Inc. There are various ways you can achieve communications in .NET world. For communicatons through internet, you can either use the awesome WCF technology, use the barebones WebRequest Class, etc. For this project, I've used the power of Web Service technology.

It's a little bit tricky to create a Web Service in a Visual Studio 2010 Class Library Project because currently, WCF is the default tool to do it. Anyhow, here's how I do it:

1. First, right click on the Class Library Project in Solution Explorer and click "Add Service Reference".




2. On the Add Service Reference Dialog, click Advance.



3. On the Service Reference Settings, click Add Web Reference.



4. On the Add Web Reference Dialog, type in the URL address box the URL address of the service that you wish to communicate. In my project, URL is  http://207.207.160.4:80/axis2/services/EventLogService?wsdl


After you type in the url, if Visual Studio's been able to communicate with the service, it will display the methods available in the service. In my case, there are only 2 methods - event_action and get_events methods.
You can change the Web Reference name if you wish. In my project, I've renamed it from WebReference to EventLogReference.

5. After you've done the above successfully, you should be able to see the EventLogReference in Web References folder.

 
6. Behind the scenes, Visual Studio automatically generated a lot of codes for you for communicating to the specified service. All you need to do is to use the generated codes and call the appropriate methods.

In my project, Visual Studio generated the EventLogService class. I need to create an instance of this service and call either of the 2 available methods - eventaction and get_events methods. In my project, I will be using the event_action method. Based from the above display, this method requires an ActionRequestType object as a parameter.

Finally, here's the code in VB.NET on how to instantiate the required parameters and call the appropriate method: The code that you use must be based on how the method that you want to call must be called.



'create CREATE ACTION TYPE
Dim actType As ACTIONType = New ACTIONType()
actType.NAME = "create"

'create ACTIONREQUESTType 
Dim actionRequesttype As ACTIONREQUESTType = New ACTIONREQUESTType()
actionRequesttype.ACTION = actType

'call Service
Dim eventLog As EventLogService = New EventLogService()

Dim response As ACTIONRESPONSEType = eventLog.event_action(actionRequesttype)

If Not response Is Nothing AndAlso Not response.ACTIONSTATUS Is Nothing _
   AndAlso Not response.ACTIONSTATUS.PARAM Is Nothing _
   AndAlso response.ACTIONSTATUS.PARAM.Count > 0 _
   Then
   result = response.ACTIONSTATUS.PARAM(0).VALUE
End If


1 comments:

Unknown said...

Hi, A writers website would include a biography, a catalog of published books and works, perhaps excerpts from some works in Web Design Cochin, links to publications on sites, a link to the writer's blog, reviews and comments on the author's publications. You get the idea, and that is to build a following, a fan base to which future publications can be directly marketed. Thanks......

Post a Comment