Manni is correct. If you pass a dataset as a return type
of a WebMethod, The WebService automagically serializes it
for you.
A real simple example of passing in XML to a WebService is
like this and using it to populate a server-side dataset
is this:
(First, assume that you have a WebRefernece to your
WebService)
localhost.WebServiceTest oTest = new
localhost.WebServiceTest();
oTest.DoSomething
("<test_data><test1>blarf</test1><test2>blarf
again</test2></test_data>");
Then on the WebService:
[WebMethod]
public string DoSomething(string XMLIn)
{
XmlDocument xDoc = new XmlDocument();
XmlTextReader xRead = new XmlTextReader(XMLIn);
DataSet dsData = new DataSet("test");
dsData.ReadXml(new XmlTextReader(XMLIn));
//Do whatever you need to do with the data here...
}
IMHO, passing XML back up to the web service tends to be
faster than doing a serialization and then passing a
dataset up. Even though the serialization happens behind
the scenes, it still consumes more resources than just
sending plain, ASCII data. If you have an existing
dataset, you can, for a lower penalty, pass it using
the .GetXml method and pass that for a string. It is less
expensive than serialization and returns plain XML for you
to pass up to the server.
Anyhow, there are a number of different ways to
communicate data up to the WebService, this is just one
opinion. :)
HTH,
Bill Priess
>-----Original Message-----
>I got this working without making my dataset serializable.
>I was making a real fundamental mistake of
>Ctyping "a generic dataset" into a typed dataset. Instead
of Ctyping , i
>merged it into the typed dataset and it works ok.
>
>I haven't tried passing XML (instead of a dataset) to a
webservice and get
>it back as a DS. Is there an example somewhere i could
see?
>I am doing bulk updates in a dataset. Can i still use XML
instead of DS ?
>
>But, isn't there some overhead to
>a. Convert my Dataset into XML ?
>b. figure out how to do block updates with XML (instead
of dataset where all
>the mechanism is already done for you)
>
>(Thanks to a coworker, who helped me spot this error)
>
>"Bill" <billpriess@southernwine.com> wrote in message
>news:177a01c2b755$de9f4c00$d3f82ecf@TK2MSFTNGXA10...
>> Yes, the error is entirely correct. You cannot pass an
>> object to a WebService unless it is serialized first.
>> Also, you cannot pass an object from a WebService unless
>> it is also serialezed first.
>>
>> WebServices only deal in two things: SOAP and XML. In
>> order to pass a DataSet to a WebService, you must
>> serialize the DataSet, then pass it to the WebService
and
>> have the WebService deserialize it.
>>
>> Why are you passing a DataSet to begin with? A couple of
>> better solutions might be to pass straight XML data,
have
>> the WebService return it to you as a serialzed DataSet,
or
>> if the WebService has access to the database, then have
>> the WebService get it's own data to validate and return
a
>> code to the consumer.
>>
>> IMHO :)
>>
>> HTH,
>> Bill Priess
>> >-----Original Message-----
>> >Hello guys,
>> >
>> >I am trying to pass a Dataset from asp.net page to a
>> Webmethod
>> >(ValidateAccountDS in a different solution) which
Ctypes
>> that dataset into a
>> >typed dataset and processes it.
>> >
>> >I am getting
>> >"System.Web.Services.Protocols.SoapException: Server
was
>> unable to process
>> >request. ---> System.InvalidCastException: Specified
cast
>> is not valid. at
>> >PMSLPWebService.PMSLPWeb.ValidateAccountDS(DataSet
ds) "
>> message.
>> >
>> >Any clues where (is it the soap call that is failing or
>> the webmethod ) and
>> >why it is happenning ?
>> >
>> >Regards
>> >
>> >
>> >
>> >.
>> >
>
>
>.
>