0

I'm about to call a webservice created in C#, that takes a parameter

KmlSystemVariable[] sysVariables

How can I pass a parameter like that using GroovyWS? It doesn't need to have any values, could be an empty array. Looks like the full class name is Consorte.Pulse.Data.KmlSystemVariable

I enabled logging as described in GroovyWS and complex requests to get the namespace for KmlSystemVariable, and it looks like I can create a KmlSystemVariable with:

proxy.create("org.datacontract.schemas._2004._07.consorte_pulse.KmlSystemVariable")

But how do I create an array of KmlSystemVariable?

Community
  • 1
  • 1
rlovtang
  • 4,860
  • 2
  • 30
  • 30

1 Answers1

1

It should be enough to just wrap your proxied objects into a Groovy list and use it as the parameter. GroovyWS will do the transformation from List to SOAP array for you behind the scenes.

Example:

def ksv1 = proxy.create("org.datacontract.schemas._2004._07.consorte_pulse.KmlSystemVariable")
def ksv2 = ...
def ksv3 = ...
def list = [ksv1, ksv2, ksv3]
proxy.<some ws method>(list)
xlson
  • 2,677
  • 1
  • 20
  • 11
  • Thanks xlson, I will try when I'm back from vacation. – rlovtang Jul 12 '11 at 22:25
  • Unfortunately, I get javax.xml.bind.JAXBException: class java.util.ArrayList nor any of its super class is known to this context. – rlovtang Jul 24 '11 at 18:51
  • That's quite strange, I'm almost certain we do something like this at work. Will check when I get back on thursday. – xlson Jul 31 '11 at 17:36
  • This seems to work: def sysvar = webService.create("org.datacontract.schemas._2004._07.consorte_pulse.KmlSystemVariable") sysvar.name = "foo" sysvar.value = "bar" def sysvars = webService.create("org.datacontract.schemas._2004._07.consorte_pulse.ArrayOfKmlSystemVariable") sysvars.kmlSystemVariables << sysvar – rlovtang Jul 31 '11 at 21:04
  • sorry, can't figure out how to format code in comments, or even adding line breaks – rlovtang Jul 31 '11 at 21:06
  • It also looks like I am able to send null as well, as I don't need to pass along any sysvariables. I first thought this didn't work, as I got an error message saying "Specified cast is not valid." But now I found out it was one of the other 14 parameters that was wrong... – rlovtang Jul 31 '11 at 21:10
  • Not quite following your last comment, does it work now or not? :) – xlson Aug 05 '11 at 09:04
  • btw, I just recently consumed a different web service, where I needed to create a list with [obj1, obj2, obj3]. But for the web service in this question, I needed to create the special type ArrayOfKmlS‌​ystemVariable. Maybe it depends on if the web service expects a native array or some kind of collection. – rlovtang Aug 05 '11 at 20:53
  • Good to hear! Ah, yeah I think it depends on if "native" soap arrays are used or not. – xlson Aug 08 '11 at 11:53