Returning an object from a Webservice

How can I reassign an object from a web service:

[WebMethod] public DataSet GetVendors (database string) {SqlConnection sqlConn = new SqlConnection ();

        sqlConn.ConnectionString = GetConnString(Database);

        // build query
        string strSQL = @"  SELECT      [No_] AS [VendorNo],
                                        LTRIM([Name]) AS [VendorName]

                            FROM        [********_$Vendor]

                            WHERE       LEN(RTRIM([Name])) > 0 /* avoid blank names */

                            AND         [Vendor Posting Group] = 'VEND'

                            ORDER BY    LTRIM([Name]) ASC; /* LTRIM fixes spaces before name */ ";

        SqlDataAdapter da = new SqlDataAdapter(strSQL, sqlConn);

        DataSet ds = new DataSet();

        da.Fill(ds, "Vendors");

        return (ds);
    }

      

0


source to share


6 answers


If I am interpreting your question correctly, fill in the object at its end with your information in DataSet

and set the return type to a value object

. Or, just return the object you are populating as that object.



+1


source


An alternative would be to return the xml dataset as a string and create a dataset from it on the client side.



While I'm sure encrypting an object would be pretty straightforward, this approach helped me when my web services needed encryption (serialize everything, encrypt this string, return the string, decrypt, deserialize).

0


source


If you are asking how to return any object, not Object

, you will need to serialize that object. If you are trying to serialize DataSet

, I would suggest creating it in List

or some other data structure first.

0


source


Seems fragile to me The client is expected to know how to deserialize this object, which blocks the client on a specific platform (such as Java EE or .NET).

XML serialization is less fragile because it is platform-agnostic and leaves unmanaged quirks that must be resolved by the client. I would recommend this for returning an object.

0


source


Another reason not to return a DataSet is "fuzzy abstraction": why expose the client to anything related to the persistence layer? Rethink it.

0


source


IMO returning datasets from your web services is not such a great idea. It assumes that clients understand the data structures and classes of Dataset, DataTable, etc. Instead, I recommend that you use a simple CLR object, that is, data transfer objects, or if you want you can use XmlNode as the data type. You can secure your web service with WSE.

0


source







All Articles