Skip to main content

Creating a Collection to Return from a Web Method

In certain situations you might want to return a collection from a Web Method. You can use Caché collections to do this.

You must, however, specify the type of the elements stored in the collection. There are two approaches to doing this.

  1. Create a new collection type by extending the Caché collection type. Specify the type of the elements stored in the collection by setting the value of the ELEMENTTYPE parameter to the appropriate type. Note that this approach works for both lists and arrays. Always use this approach for arrays.

  2. Set the value of the ELEMENTTYPE parameter for the collection type. For example, here is the signature of a WebMethod that returns a %ListOfObjectsOpens in a new tab collection that contains instances of SOAPTutorial.Contact. This approach works only for lists.

    
    Method GetContacts() As %ListOfObjects(ELEMENTTYPE="SOAPTutorial.Contact") 
    [WebMethod]   
    

The following example demonstrates the first approach.

Here are the steps for using the Studio New Class Wizard to create a collection type, named ContactList, that can be used to return a collection of Contact instances from SOAPService:

  1. Click File -> New.

  2. Click the General category, and then click the Cache Class Definition icon.

  3. Specify that new class is part of the SOAPTutorial package and that its name is ContactList. Click Next.

  4. On the Class Type Screen click Extends. Click the Browse button and then click %Library.ListOfObjectsOpens in a new tab.

    generated description: newclasswizard1 20142

  5. Click Finish.

  6. In the Class Editor assign the value “SOAPTutorial.Contact” to the ELEMENTTYPE parameter. This specifies that instances of ContactList contain collections of Contact objects:

    Class SOAPTutorial.ContactList Extends %Library.ListOfObjects 
    {
    
    Parameter ELEMENTTYPE = "SOAPTutorial.Contact";
    
    }
    
  7. Click Build —> Compile to compile the new class.

FeedbackOpens in a new tab