Skip to main content

This is documentation for Caché & Ensemble. See the InterSystems IRIS version of this content.Opens in a new tab

For information on migrating to InterSystems IRISOpens in a new tab, see Why Migrate to InterSystems IRIS?

Web メソッドでのコレクションの使用

ContactList オブジェクトを使用して、Contact オブジェクトのリストを SOAPService Web メソッドから返します。以下のメソッド GetContactByName は、指定された文字列で始まる Name 値を持つ Contact インスタンスをすべて検索するクエリを実行します。このメソッドは、検索された各インスタンスを ContactList オブジェクトに追加し、そのコレクションをクライアントに返します。

スタジオ・クラス・エディタを使用して、以下のメソッド定義を SOAPService に追加し、[ビルド]→[コンパイル] をクリックして 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