Tutorial :Return tabular structure from Web service



Question:

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.


Solution:1

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


Solution:2

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.


Solution:3

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

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


Solution:4

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.


Solution:5

You could return something like a Fielded Text value. There sadly isn't a library to easily build such text objects in .Net but it's quite simple to implement it yourself and can definitely be parsed by any other platform.

By the way, do you really need to use a SOAP based web service? It could perhaps simply be a text document returned when you call a given url. Consider taking a look at a RESTful web service.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »