Skip to main content

Adding a Web Method

A Web Method is a method exposed as a Web Service. SOAP clients have access to the method. As previously noted, Web Methods are ordinary Caché methods meeting the following criteria:

  • They are tagged with the WebMethod attribute.

  • Any objects that they return or accept as arguments are XML-enabled. That is, they are instances of classes that extend %XML.AdaptorOpens in a new tab.

  • In general Web Methods should be instance methods, although ClassMethods will work. In most cases you will want to control properties of your Web Service class from within the Web Method and will therefore need to use instance methods.

The following method retrieves the Contact instance with the specified id value and returns it to the client. Clients of the Web Service can use the method to retrieve Contact instances from Caché. Using the Studio Class Editor, add the method to your SOAPService class and then compile the class by clicking Build —> Compile.

Method GetContact(id As %String) As SOAPTutorial.Contact [ WebMethod ]
 if ##class(SOAPTutorial.Contact).%ExistsId(id){
  quit ##class(SOAPTutorial.Contact).%OpenId(id)
 else {
  quit ""   
FeedbackOpens in a new tab