开发者

Return tabular structure from Web service

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.


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


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.


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

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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜