Skip to main content

Using a Collection in a Web Method

Use a ContactList object to return a list of Contact objects from a SOAPService Web Method. The following method, GetContactByName, executes a query to find all the Contact instances with a Name value that begins with a specified string. The method adds each such instance to a ContactList object and returns the collection to the client.

Use the Studio class editor to add the following method definition to SOAPService and then click Build —> Compile to recompile SOAPService.

Method GetContactByName(name As %String) 
As SOAPTutorial.ContactList [ WebMethod ]
 set rs=##class(%ResultSet).%New("%DynamicQuery:SQL")
 set query="SELECT %Id FROM SOAPTutorial.Contact WHERE Name %STARTSWITH ?"
 set list=##class(SOAPTutorial.ContactList).%New()
 do rs.Prepare(query)
 do rs.Execute(name)
 while rs.Next()
  set ref=##class(SOAPTutorial.Contact).%OpenId(rs.Get("ID"))
  do list.Insert(ref)
  quit list
FeedbackOpens in a new tab