views:

163

answers:

4

Whats the best way to return a tabular structure from an ASP.NET (2.0) web service?

It should be inter-operable with Java, Iphone App or any other platform.

EDIT: By inter-operable I mean the other technology/client should be able to consume it or deserialize it to their native types, instead of parsing response XML.

+1  A: 

You can achieve interoperability by using SOAP/XML. Here's a link to an article that may be helpful to you.

ChadNC
+1  A: 

Web Services by definition are interoperable because of, among other things, they rely on XML to pass data among heterogeneous systems.

That said, what needs to be defines is how the tabular structure is serialized in XML.

There are several ways to do it, everyone of them has its pros and cons.

  • Implement the ISerializable interface
  • Decorate the class with [XmlSerializer] attributes to control how the class is serialized as XML.
  • etc, etc, etc...

Simply start to define how do you want to express your tabular data, and then work in how to implement.

Paulo Santos
You mean any tabular structure I send through a web service will be easily consumed by any client (java, php). How about returning DataTable or DataSet (.NET)? I don't think it's that simple.
noob.spt
A: 

http://support.microsoft.com/kb/306134

I think on this page . you will get the answer.

Sikender
A: 

Depends on your preferred format. I'd suggest:

if XML then something like:

<table>
  <row1>
    <col1>data</col1>
    <col2>data</col2>
  </row1>
  <row2>
    <col1>data</col1>
    <col2>data</col2>
  </row2>
</table>

if JSON then something like:

[{"col1":"data","col2":"data"},{"col1":"data","col2":"data"}]

In any case, it's best not to do this by hand. Use a library to serialize your data.

slebetman
I will be using ASP.NET and I can serialize DataTable to structure similar to suggested above. I am not sure about deserialization.
noob.spt
I'm sure ASP.NET has libraries to serialize XML and JSON. I'd be very surprised if Microsoft is still living in the dark ages. (come to think of it, I know they have libraries to handle XML because they're currently getting sued by a patent troll for it)
slebetman