Skip to main content

Adding a Query

You can add a method that executes a query to your Web Service class. For Caché Web Services that are to be used by .NET clients, Caché provides the class %XML.DataSetOpens in a new tab to return query results using SOAP. %XML.DataSetOpens in a new tab is a SOAP-enabled subclass of %Library.ResultSetOpens in a new tab. .NET client applications automatically convert the returned SOAP message into .NET DataSet objects.

To use %XML.DataSetOpens in a new tab do the following:

  1. Specify %XML.DataSetOpens in a new tab as the return type of your Web Method.

  2. Instantiate a new %XML.DataSetOpens in a new tab 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.DataSetOpens in a new tab 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:

  • The associated Contact instance has the id value specified by the query parameter.

  • The PhoneNumberType has the specified value.

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)
 quit query
}
FeedbackOpens in a new tab