Returning a DataSet from Webservices

Discussion in 'ASP .Net Web Services' started by raheel hussain, May 19, 2004.

  1. 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
    raheel hussain, May 19, 2004
    #1
    1. Advertising

  2. you have a null pointer.

    how do you initialize objWebService ?


    "raheel hussain" <> wrote in message
    news:...
    > 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
    Dino Chiesa [Microsoft], May 19, 2004
    #2
    1. Advertising

  3. 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


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Raheel Hussain, May 19, 2004
    #3
  4. 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

    "Raheel Hussain" <> wrote in message
    news:...
    >
    >
    > 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
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
    Dino Chiesa [Microsoft], May 19, 2004
    #4
  5. hi,

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

    thankx a lot.

    regards

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Raheel Hussain, May 20, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SMG
    Replies:
    4
    Views:
    3,524
  2. Espen Dietrichs

    WebServices returning a java.util.Vector

    Espen Dietrichs, Aug 21, 2003, in forum: Java
    Replies:
    0
    Views:
    4,097
    Espen Dietrichs
    Aug 21, 2003
  3. Replies:
    2
    Views:
    536
  4. Mario Rodriguez

    problems returning ArrayList from webServices

    Mario Rodriguez, Apr 12, 2004, in forum: ASP .Net Web Services
    Replies:
    5
    Views:
    160
    Jan Tielens
    Apr 15, 2004
  5. Ashish Saxena via .NET 247

    Returning ArrayList from WebServices

    Ashish Saxena via .NET 247, Apr 8, 2005, in forum: ASP .Net Web Services
    Replies:
    2
    Views:
    117
    Krishna
    Apr 11, 2005
Loading...

Share This Page