Variable number of arguments in web service method

I wonder if you could help me? I have a regular cache class that accepts a variable number of arguments in one of the methods. It works fine so I decided to add a method to my web service to make the call to the cache class. I get a compile error on the web service with error#5130.

Here is the cache class

class method GenerateFileFromSQL(file As %String, sql As %String, delimiter As %String = "", args...) As %Status

and here is the web service code that calls it:

ClassMethod GenerateFileFromSQL(file As %String, sql As %String, delimiter As %String = "", args...) As %String [ WebMethod ]
 

Please note that the code in the regular cache class compiles fine and runs without any issues. The web service seems not to accept the variable parameter args...

Any suggestions?

Thank you,

Everardo

 

  • 0
  • 0
  • 290
  • 0
  • 2

Answers

Hi Everardo,

There is an extra couple of compilation steps required for the web method.

Each web method requires its own separate message descriptor class. This class contains the arguments of your method as properties of the class, e.g.
 

Property file As %Library.String(MAXLEN = "", XMLIO = "IN");
Property sql As %Library.String(MAXLEN = "", XMLIO = "IN");


This extra class is required to provide a concrete API to your web method. The web service description will project this class as a complex type that the calling services needs to adhere to.

What I think is happening is that when you have an argument called args... that the compiler is trying to compile
 

Property args... As %Library.String(MAXLEN = "", XMLIO = "IN");


Which would fail with an invalid member name error (which correlates with the 5130/5030 error code you have).

I think the main issue here is that there is nothing (to the best of my knowledge) in the SOAP specification that allows for variadic types.

Instead what you want is an argument type that can be projected as a list or an array, e.g.
 

ClassMethod GenerateFileFromSQL(file As %String, sql As %String, delimiter As %String = "", args As %ListOfDataTypes) As %String [ WebMethod ]


That will then be projected in the WSDL as a complex type with an unbounded max occurs, allowing the client to send any number of repeating XML elements for the property args.

If you pass args as %ListOfDataTypes to your non web method then you will need to decide if that method should have the same formal spec, or overload it, something like...
 

if $IsObject(args(1)),args(1).%IsA("%Library.ListOfDataTypes") {
  set list=args(1)
  for i=1:1:list.Count() {
    write !,list.GetAt(i)
  }
} else {
  for i=1:1:args {
      write !,args(i)
  }
}


Sean.

Sean,

Thank you so much for the answer! My other option is to use a json string and de-serialize it in my service class.

Cheers,

Everardo