Webservice Macro Example - using DataTable as resulttype

From Smartsite iXperion 1.2 onward, the webservice macro now also supports DataTable as return type. To use this new feature, you just need to set the ResultType property to datatable. (Note: the incoming response is loaded into a DataSet and at the moment, by default, the first table found within the Tables collection of this DataSet will be returned.)

When the result is loaded into a datatable, you can use standard formatting to format the result, without the need to write xslt (which you would usually need to do, since an XmlReader is returned by default).

The webservice being called must of course return data which can be loaded into a DataTable. The Bing Search webservice example, for example, isn't an appropriate candidate for using this new feature, since this webservice returns its result in a strong hierarchical xml format.

When the webservice does actually return a datatable, you would also need to set the readschema property to true, because the serialized datatable includes inline schema information. The example below calls the asmx webservice example, which have been expanded with the following method:

C# CopyCode image Copy Code
[WebMethod]
public DataTable returnDataTable()
{
  DataTable table = new DataTable("Table");
  table.Columns.Add("name");
  table.Columns.Add("value");
 
  DataRow row = table.NewRow();
  row[0] = "first name";
  row[1] = "first value";
  table.Rows.Add(row);
 
  row = table.NewRow();
  row[0] = "second name";
  row[1] = "second value";
  table.Rows.Add(row);
 
  return table;
}

Notice, for demonstration purposes, this example just simply uses the datatable.simpleformat viper to format the datatable.

Smartsite SXML CopyCode image Copy Code
<se:webservice resulttype="datatable" save="result">
    <se:parameters>
        <se:parameter name="url">http://localhost/TestWebservice.asmx</se:parameter>
        <se:parameter name="soapaction">http://smartsite.nl/returnDataTable</se:parameter>        
        <se:parameter name="methodname">returnDataTable</se:parameter>
        <se:parameter name="methodnamespace">http://smartsite.nl/</se:parameter>
        <se:parameter name="readschema">true</se:parameter>
    </se:parameters>
</se:webservice>

{datatable.simpleformat($result)}