Results 1 to 6 of 6

Thread: [RESOLVED] [Help] returning an SqlDataReader in WCF Service ASP.NET-VB

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2015
    Location
    Indonesia
    Posts
    16

    Resolved [RESOLVED] [Help] returning an SqlDataReader in WCF Service ASP.NET-VB

    i have a WCF web service that have a function named "GetData" returning a SQLDataReader type.
    the problem is when i try to access "GetData" function from my code, i get compiler error Value of type '1-dimensional array of Object' cannot be converted to 'System.Data.SqlClient.SqlDataReader'.
    this is really frustrating me. anyone please help me. thanks, before. really appreciate it.

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [Help] returning an SqlDataReader in WCF Service ASP.NET-VB

    It has been a while since I did any web service work, but if I remember right, the web service can't return complex object types like a SQLDataReader, only objects that can be serialized in order to be transported across the webservice. You can create a dataset object that you fill with record data on the ASP.NET side of things and pass that over the web service, since dataset objects can be serialized.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2015
    Location
    Indonesia
    Posts
    16

    Re: [Help] returning an SqlDataReader in WCF Service ASP.NET-VB

    Quote Originally Posted by kleinma View Post
    It has been a while since I did any web service work, but if I remember right, the web service can't return complex object types like a SQLDataReader, only objects that can be serialized in order to be transported across the webservice. You can create a dataset object that you fill with record data on the ASP.NET side of things and pass that over the web service, since dataset objects can be serialized.
    that's what i thought too, but i have to make sure to myself. i can call the function in wcf service when i use a dataset. weel i guess i'll use your advice.
    but i wonder if i can pass my own class as a return value. is it possible?

    p.s. i'm sorry for my english so poor

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,300

    Re: [Help] returning an SqlDataReader in WCF Service ASP.NET-VB

    A data reader is an object that executes a query and then provides access to the result set created by the database. Each time you call Read, it reads a record from the database. If your web service was to return a data reader, how could the client expect to call Read and get a record from the database? As kleinma says, you need to execute the query and retrieve the entire result set and package that up and return it. That would mean calling Load on your data reader and populating a DataTable or else using a data adapter to populate a DataTable. You can then return the DataTable as is or as part of a DataSet.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Aug 2015
    Location
    Indonesia
    Posts
    16

    Re: [RESOLVED] [Help] returning an SqlDataReader in WCF Service ASP.NET-VB

    thanks for the help. i decided to use the dataset. thank you very much guys

  6. #6
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: [RESOLVED] [Help] returning an SqlDataReader in WCF Service ASP.NET-VB

    If I may - If all you are going to return is a single table, I'd suggest using a DataTable, less over head. I'd only use a DataSet if you were returning more than one tble in a single call.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width