• 0

Serialize Dataset contained in a Class


Question

Hello guys!

I'm creating some webservices that return a class I created.

This class contains the following:

string datatype;

Object data;

boolean error;

string errormessage;

This works fine when data has types like String, but it doesn't work when it is DataSet.

I get the following error (excerpt):

System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: The type System.Data.DataSet may not be used in this context. To use System.Data.DataSet as a parameter, return type, or member of a class or struct, the parameter, return type, or member must be declared as type System.Data.DataSet (it cannot be object). Objects of type System.Data.DataSet may not be used in un-typed collections, such as ArrayLists.

at System.Xml.Serialization.XmlSerializationWriter.WriteTypedPrimitive(String name, String ns, Object o, Boolean xsiType)

...........

.............

..............

I need this class to be data independent, so i need it to be Object.

Thank you

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0
Hello guys!

I'm creating some webservices that return a class I created.

This class contains the following:

string datatype;

Object data;

boolean error;

string errormessage;

This works fine when data has types like String, but it doesn't work when it is DataSet.

I get the following error (excerpt):

I need this class to be data independent, so i need it to be Object.

Thank you

I'm guessing the Webservice is done in C#. Your not allowed to return objects over a webservice in C#, unless they are XML Serializable.

The way i find easiest to use is to generate an XML Document containing the properties of the object and return it to the client as a string, ready to convert back into the desired object.

I do believe standard built-in types are supported over web-service, (int, bool etc), just not User-Created Objects Unless they implement the correct interface for serialization.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.