4

I'm looking to consume a SOAP web service which requires an object to be passed as a parameter e.g.

<cfset someVariable = createObject("webservice", "http://www.example.com/webservice")>

Which has a method

someMethod(org.example.schemas._2004._07.example_api_objects.Example)

Example is a complex object with a number of properties, methods etc. I can access the relevent stub file relating to Example in ColdFusion10\cfusion\stubs\WS403970439_1\org\example\schemas._2004._07.example_api_objects and have found that if this is added to the class path I can use the following:

<cfset someExample = CreateObject("java", "org.example.schemas._2004._07.example_api_objects.Exampler").init()>
<cfset someVariable.someMethod(someExample)>

I'm sure I should be able to create the someExample object directly through ColdFusion without needing to add the relevant stub files to the classpath, but I haven't been able to do this - does anyone know how this might be possible?

CFML_Developer
  • 1,565
  • 7
  • 18
Loftx
  • 1,760
  • 4
  • 29
  • 50
  • Is the webservice written in ColdFusion? – Dan Bracuk May 09 '14 at 12:32
  • @DanBracuk - No the webservice is written in .NET – Loftx May 09 '14 at 12:56
  • You can usually represent complex objects as structures. Can you post a link to the wsdl -or- a sanitized version of the wsdl description of that method and complex type. – Leigh May 09 '14 at 15:26
  • (Edit) *RE: I'm sure I should be able to create the someExample object directly..* Yes and no. The classes must in the classloader (or parent's) class path. However, it can be [done dynamically](http://stackoverflow.com/a/15592095/104223) using the JavaLoader (or CF10's version of it). Having said that, it is a bit more complex and I am not convinced you even need to go that route.. Try using cf structures to represent the complex object first. But again, we need to see the wsdl definitions to assist you with that. – Leigh May 09 '14 at 18:07

1 Answers1

1
<cfset someExample = someVariable.getClass().getClassLoader().loadClass('org.example.schemas._2004._07.example_api_objects.Example').newInstance() />

Then just use the setters and getters on the someExample object to set your values...

Doing it the other way is not robust enough. What if the wsdl changes?

dkimbell13
  • 123
  • 7