Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can we pass dataset to a web service method? If yes , then how?

can we pass dataset to a web service method? If yes , then how?

like image 884
NayeemKhan Avatar asked Feb 11 '11 06:02

NayeemKhan


3 Answers

IIRC, "yes" (just have a DataSet parameter), but also "you shouldn't"; while .NET may know how to process it, web-services are meant to be interoperable based on xml entities; a DataSet (even when serialized as xml) is about as far away from that as you can get. IMO it would be a better idea to write some basic classes that represent your model, and expose those to the web service, as they can be properly represented in xsd for SOAP purposes.

like image 182
Marc Gravell Avatar answered Nov 13 '22 09:11

Marc Gravell


Passing a DataSet to a webservice is not a good idea. Instead use DataSet's ReadXML or WriteXML methods to pass data to webservice and read it at webservice end.

Edit: If possible create separate classes as Marc Grawell said, if that's not feasible for you (which is a rare case) then you can use above methods to pass data for better approach than passing DataSet directly.

like image 21
JPReddy Avatar answered Nov 13 '22 09:11

JPReddy


Marc is right about the dataset. It is probably one of the worst design principles you can do. However you should not construct your datacontracts the way you represent you model. The SOAP messages you construct should be defined as messages. You are not sending objects over the wire but SOAP messages. You can then use one of your object models incapsulated by that message, but do not send it as an object itself.

Working message based allows you more control over things like secuity headers and faulths.

http://msdn.microsoft.com/en-us/library/ms734675.aspx

like image 1
Luc Bos Avatar answered Nov 13 '22 09:11

Luc Bos