Home  /  Application Development: Additional Options  /  Web Services Quick Start Tutorial  /  Publishing Web Services Using InterSystems IRIS  /  Using a Collection in a Web Method

Web Services Quick Start Tutorial
Using a Collection in a Web Method
[Back]  [Next] 
InterSystems: The power behind what matters   

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 Atelier to add the following method definition to SOAPService and then recompile SOAPService.
Method GetContactByName(name As %String) 
As SOAPTutorial.ContactList [ WebMethod ]
    set list=##class(SOAPTutorial.ContactList).%New()
    set query="SELECT %Id FROM SOAPTutorial.Contact WHERE Name %STARTSWITH ?"
    set stmt = ##class(%SQL.Statement).%New()
    set status = stmt.%Prepare(query)
    set rs = stmt.%Execute(name)
    while rs.%Next()
        set ref=##class(SOAPTutorial.Contact).%OpenId(rs.ID)
        do list.Insert(ref)
    return list