Best practice to define multi-dimensional arrays in wsdl

Tag: wsdl Author: room08 Date: 2011-09-08

I'm developing a WebService with a function which returns a database result, which means an MxN array. My question is, what's the better way to define this in wsdl:

  1. Define a row as sequence of (string) columns, define the resultset as sequence of rows, put this resultset into a message
  2. Define a row as sequence of (string) columns, put a sequence of such rows into the message directly

So is it better/cleaner/nicer to wrap the rows into an own datatype and put this one into the response message or leave the own datatype and put the row-sequence directly into the message?

Thank you!

Best Answer

For the row you define an element which has as children elements coresponding to the columns of the result.

<row>
    <field1>...</field1>
    <field2>...</field2>
    ...
    <fieldN>...</fieldN>
</row>

You then return a wrapped list of row elements.

<rows>
    <row>
      ...
    </row>
    <row>
      ...
    </row>
    ...
    <row>
      ...
    </row>
</rows>

(I'm using row/rows here for simplicity. You can name the element whatever you want, normally a name that reflects the what the data in the row represents).

comments:

ok and after that I put the rows into my message? Just putting the row-elements into my message is no good style? It saves one Java-object that's the reason I ask ;-)
@strauberry: I understand what you are saying. Why have a wrapper when I can just write the elements directly? Is that right? Well... first thing, you make the XML more human readable as rows are grouped under a parent and second but more important is that you gain interoperability. In order to be WS-I compliant, the SOAP message's soap:body must have only one child. If you put the rows directly into your message (no parent wrapper) you violate this rule and loose interoperability. Deeper inside the message it does not matter as much but at that point you loose number one: readability.
@strauberry: Here is the starting point for best practices when using web services: en.wikipedia.org/wiki/Web_Services_Interoperability
Thank you both for your comments. The WS-I thing is very interesting :-)