5

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

3 Answers 3

7

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.

4
  • +1 even though I posted my answer to use ReadXML and WriteXML methods but I would still go with your answer to use separate classes to pass data.
    – JPReddy
    Feb 11, 2011 at 6:31
  • 1
    @Marc Gravell: how can i pass dataset from android to soap service there are any setps for that? Oct 9, 2013 at 4:16
  • 1
    @HarshalKalavadiya here's the thing: stop using DataSet. It is not the right tool for this, especially if you need to pass if over a service boundary. If the android app is native: no, not really. If it is Mono - maybe there's an outside chance. Oct 9, 2013 at 6:49
  • @Marc Gravell:Thanks for yor answer .. pls. refer this link http://stackoverflow.com/questions/19198017/pass-arraylist-data-into-soap-web-service-in-android i have to pass array of data to SOAP service so how can i pass it ? Oct 9, 2013 at 7:11
2

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.

1

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

2
  • A side note: the above mainly relates to WCF; the tooling etc for vanilla asp.net web-services is much less powerful Feb 11, 2011 at 6:43
  • Yes indeed, this can only be done using a more robust framework like WCF.
    – Luc Bos
    Feb 11, 2011 at 7:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.