How to create an ASP.NET web-page client for a web service in VB.NET

If you have a web service and a proxy class you need to develop a web-page client. Note: You can find more details about web services and proxy class by searching form them in the site.

If you are using Visual Studio as a basic environment you should:

1. To create a new web project.

2. Add a web reference to the web service.

If you are using another environment you should:

1. To compile a proxy class by using wsdl.exe.

2. Place it the new web application Bin directory.

The next example uses a simple web page with a button and a GridView control. When the user clicks the button, the web page posts back, creates the proxy class, retrieves the DataSet of books from the web service, and then displays the result by binding it to the grid.

You need to import the proxy class namespace, and then you can add the code that uses the proxy class to retrieve the data:

 

Private Sub cmdGetData_Click(sender As Object, e As System.EventArgs)

 

‘ Create the proxy.

Dim Proxy As New BooksService()

 

‘ Call the web service and get the results.

Dim Ds As DataSet = Proxy.GetBooks()

 

‘ Bind the results.

GridView1.DataSource = Ds.Tables(0)

GridView1.DataBind()

End Sub

 

You can use the Object-DataSource to bind directly to the corresponding proxy class.

 

<asp:ObjectDataSource ID=”ObjectDataSource1″ runat=”server” SelectMethod=”GetBooks” TypeName=”localhost.BooksService” />

 

<asp:GridView ID=”GridView1″ runat=”server” AutoGenerateColumns=”True”

DataSourceID=”ObjectDataSource1″/>

 

Note:

From the point of view of your web-page code, there’s no difference between calling a web service and using an ordinary stateless class. You need to reduce the number of times you call the web service and be to handle exceptions resulting from network problems and connectivity errors. The basic reason for that is the fact that the web service that actually implements the business logic could be on a web server on the other side of the world.