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);
}
source to share
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).
source to share
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.
source to share
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.
source to share