This post provides my implementation of returning recordsets with SOAP messaging. A more complete article is Returning ADO Recordsets with SOAP Messaging by Chris Dengler.

Recordset to be retrieved

A DLL on the web server took certain parameters and returned a recordset containg employee information. My web service offered the facility to retrieve this information in the form of a simple XML representation.

Schema Generated by the Wizard

The SDL wizard generated the following schema for the response with the return type defaulted to string:

  <element name='GetEmployeeResponse'>
      <element name='return' type='dt:string'/>

Edited Schema

I adjusted the schema to my own structure so that the SOAPPackager on the client end knew that it was receiving XML rather than the string:

  <element name='GetEmployeeResponse'>
      <element name='return' type='GetEmployeeStruct'/>
      <element name='pvarResults' type='dt:string'/>
      <element name='pvarErrors' type='dt:string'/>
  <element name='GetEmployeeStruct'>
      <element name='RECORD' type='GetEmployeeRecStruct'/>
  <element name='GetEmployeeRecStruct'>
      <element name='intEmpID' type='dt:integer'/>
      <element name='strUserName' type='dt:integer'/>
      <element name='strFirstName' type='dt:string'/>
      <element name='strSurname' type='dt:string'/>
      <element name='strEmail' type='dt:string'/>

Adjusted ASP Function

The ASP function was then adjusted to pass an ADO recordset into the DLL call as opposed to a string, and a simple XML representation of that database is returned by the web service.

  ' function used by the listener
  Public Function GetEmployee (ByVal plngUserID)
    Dim objGetEmployee
    Set objGetEmployee = Server.CreateObject("MyPackage.MyClass")
    Dim objRS		' record set object to pass to function
    ' create disconnected recordset
    Set objRS = Server.CreateObject("ADODB.Recordset")
    ' call function - function will return objRS as a disconnected recordset
    Call objGetEmployee.GetEmployee(plngUserID, objRS)
    ' convert the recordset into XML format and send back to client
    GetEmployee = GetXMLFromRS(objRS)
    ' clean up objects
    Set objRS = Nothing
    Set objGetEmployee = NOTHING
  End Function
  ' function used to convert the recordset to XML
  Function GetXMLFromRS(ByVal objRS)
    ' declare variables
    Dim strXML					' output XML string
    Dim objField				' fields in the record set
    Dim strFieldName		' name of the field
    Dim strFieldValue		' value of the current field in the current record
    ' create outer element RECORDSET
    strXML = "<RECORDSET>" & vbCrLf
    ' loop through the recordset, adding each record and values to string
    Do While NOT objRS.EOF
      ' add new RECORD element for each record
      strXML = strXML & vbTab & "<RECORD>" & vbCrLf
      ' loop through the fields and add each with value to xml string
      For Each objField In objRS.Fields
        strFieldName = objField.Name
        strFieldValue = CDATAIt(objRS(strFieldName))
        strXML = strXML & vbTab & vbTab & "<" & strFieldName & ">" _
        & strFieldValue & "</" & strFieldName & ">" & vbCrLf
      ' close RECORD element
      strXML = strXML & vbTab & "</RECORD>" & vbCrLf
    ' close outer element RECORDSET and return XML string
    strXML = strXML & "</RECORDSET>" & vbCrLf
    GetXMLFromRS = strXML
    ' GetXMLFromRS = "Test"
  End Function

  ' function to add cdata tags to XML information
  Function CDATAIt(ByVal strXMLVal)
	  CDATAIt = "<![CDATA[" & strXMLVal & "]]>"
  End Function


The result returned is straight-forward XML, for example:

      <Email><![CDATA[[email protected]]]></Email>
      <Email><![CDATA[[email protected]]]></Email>