Reputation: 361
I am trying to consume a WSDL from ColdFusion using cfinvoke tag and I am having problems passing arguments. If it's a simple STRING or NUMERIC argument, it works good. The problem is when I need to pass this argument:
<part name="options" type="soap-enc:Array"/>
Well, I tried different ways: pass a ColdFusion ARRAY, STRUCT, simple string, etc. Nothing works. In some cases I got a response from the web service telling that the parameter is missing and when I pass a structure, I am getting this error:
Error converting CFML arguments to Java classes for web service invocation. Unable to create web service argument class [Ljava.lang.Object;. Error: java.lang.InstantiationException: [Ljava.lang.Object;. Often this is because the web service defines an abstract complexType as an input to an operation. You must create an actual instance of this type in Java.
You can see the script in action here:
There you have the link to the web service definitions. What should I do? How do I pass simple Array objects to WSLD from ColdFusion?
Upvotes: 3
Views: 278
Reputation: 798
The lack of transparency around complex SOAP objects like you see here are a big reason why JSON is much preferred as a data format these days. I've written Java components to deal with this kind of thing. You need to know the specific format of the options variable (the second argument), which is an array of Objects, though it gives no details. I don't have a completely working solution for you, but this code should get you most of the way there.
<cfscript>
ws = createObject("webservice", "https://api.iritravel.ro/?wsdl");
res = ws.getCountries(token = "137e8f1a094-1031");
country = createObject( "java", "java.util.HashMap" ).init();
country.put( 'CountryId', 2 );
res2 = ws.getTowns( token = "137e8f1a094-1031", options=[ country ] );
writedump( res2 );
writedump( country );
</cfscript>
If I get it working I will post an update, but you might be able to get it done using what I have here. I have created a HashMap (basic Java object) and added a key "CountryId" with a value of 2. See the way I formatted the options argument as an array and passed the country HashMap object to it as the first element of the array. That bit of the code works, so you just need to know the specific format of the Object the service is expecting.
Update
I have included a SOAPUI-generated request for getTowns() which shows the problem is the same whether using webservices calls or cfhttp. In this case, I have added a CountryId parameter to the request, and what I get back is the same response I got from the previous call - param CountryId is missing. So the issue is the same - the format of the Object Array that the service is expecting to consume is incorrect.
Upvotes: 3