Home  /  Application Development: Additional Options  /  Web Services Quick Start Tutorial  /  Publishing Web Services Using InterSystems IRIS  /  Adding a Query

Web Services Quick Start Tutorial
Adding a Query
[Back]  [Next] 
InterSystems: The power behind what matters   

You can add a method that executes a query to your Web Service class. For InterSystems IRIS Web Services that are to be used by .NET clients or other InterSystems clients, InterSystems IRIS provides the class %XML.DataSet to return query results using SOAP. %XML.DataSet is a SOAP-enabled subclass of %Library.ResultSet. .NET client applications automatically convert the returned SOAP message into .NET DataSet objects.
To use %XML.DataSet do the following:
  1. Specify %XML.DataSet as the return type of your Web Method.
  2. Instantiate a new %XML.DataSet instance.
  3. Specify the SQL to be executed using Prepare. The SQL can be determined either at compile-time or runtime.
  4. Set any parameters required by the query using SetArgs.
  5. Return the %XML.DataSet instance from the method. Note that Execute is not invoked.
The following method returns the PhoneNumberType and Number values for each PhoneNumber instance meeting the following criteria:
For example, the query might be used to retrieve all of the phone number information for “Business” phone numbers for Contact 1.
Add the following Web Method to your SOAPTutorial.SOAPService class. Recompile the class.
Method RunPhoneNumberQuery(contactId As %String, 
phoneNumberType As %String) 
As %XML.DataSet [ WebMethod ]
 set query = ##class(%XML.DataSet).%New("%DynamicQuery:SQL")
 set sql = "SELECT p.PhoneNumberType, p.Number FROM SOAPTutorial.Contact" 
 set sql = sql_" as c inner join SOAPTutorial.PhoneNumber as p"
 set sql = sql_" on p.Contact=c.ID WHERE c.ID=? AND p.PhoneNumberType=?"
 do query.Prepare(sql)
 do query.SetArgs(contactId, phoneNumberType)
 return query