Monday, November 17, 2008

Passing Dataset or Datatable to WEBSERVICE

1. Open VS2005
2. Add a new Website.
3. Create a New Web Service

IN TestWebService.asmx

"Hello World" is Default Function
<WebMethod()> _
Public Function HelloWorld() As String
Return "Hello World"
End Function

Add a Function as shown below
<WebMethod()> _
Public Function PICKLIST(ByVal dsInput As Data.DataSet) As Data.DataSet
'Here dsInput is ur Table…..
'I am Returning the dataset

Return ds
End Function

Making use of this WebService in Our Application

• Open VS2005
• Add a new Website.
• Create a New Web Application
• Open Solution Explorer
• Right Click on Your Website
• Select Add Reference
• Give the Path of Your Webservice
• Add Click On “GO”
• And then Click on Add Reference
• Your Reference is added to AddReferences Folder

IN TestWebApplication.vb

Add make use of that Reference in your Page_Load
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim ObjWeb As New localhost.TestWebService
'Binding the Webservice Output to Grid
‘Here ds is ur Input Table and it will return the output

GridView1.DataSource = ObjWeb.PICKLIST(ds)
GridView1.DataBind()
End Sub
Note:Datatable may cause Problems.So Prefer dataset's.
If it is necessary convert datatable to dataset. Like
Dim ds As New Data.DataSet
ds.Tables.Add(dtTable)