Returning a DataSet from Webservices

R

raheel hussain

hi
i got a problem here in returning a Dataset from a webservice.

following is my code


in webservice
------------------------


<WebMethod()> _
Public Function GetDS(ByVal str As String) As System.Data.DataSet
'code here
cn.Open() 'connection object
Dim cmd As New SqlCommand
cmd.Connection = cn
cmd.CommandType = System.Data.CommandType.Text
Dim ds As New System.Data.DataSet
Dim da As New SqlDataAdapter(cmd)
da.SelectCommand = cmd
cmd.CommandText = "select * from Emp where sName='"&str&"'"
da.Fill(ds, "tblVehicle")
return ds
End Function




and here how i m calling it
-----------------------------
Dim ds As System.Data.DataSet
ds = objWebService.GetDS("test")

I also tried calling it as
-----------------------------
Dim ds As System.Data.DataSet=objWebService.GetDS("test")


things to note here is

- when i run the webservie in debug mode (through http://localhost/myservice.asmx)
this functions works fine and return the dataset as xml document.

- when i copy the function in my consumer application (the asp.net web application)
it works fine as a local function and returns dataset.

- but when i call it through my consumer web application through the webservice obj
it gives me the following error :

"object reference not set to an instance of object."

I require the help of you guys to sort out this.

With Best Regards
Raheel Hussain

___
Newsgroups brought to you courtesy of www.dotnetjohn.com
 
R

Raheel Hussain

hi,
I just simply added the web reference by going to the
Project Menu > Add Web Reference
in Visual Studio.net

and I m also using other functions from that web service
and all other functions are working like as

SaveCustomer(Agruments..)
SaveVehicle(Agruments..)

everything is going fine except its not returning dataset.

following is the code i used for the object of webservice.

Public Class complaints
Inherits System.Web.UI.Page
Dim _sqlStmt As String = ""
Dim obj As New LibraryFunctions
Dim Service As Service.MyService

'other code goes here

End Function


regards
 
D

Dino Chiesa [Microsoft]

where and how is objWebService initialized?

I am guessing it is not initialized, which is why you get the error.
you have to

objWebServices= New Whatever()

where "Whatever" is the name of your webservice proxy (The thing that gets
generated when you "Add Web Ref")

-D
 
R

Raheel Hussain

hi,

Yes you were right, I was not initializing the webservice, now its
working fine, with the function.

thankx a lot.

regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top