Skip to main content
Aug 16, 2006 6:11 PM UTC
Answered

Web Services - Handling complex type response

I have to consume a web service that returns an array of a complex type.
The wsdl looks as below:
Request: POST /UserManager/usermanager.asmx HTTP/1.1
<soap:Body>
<GetMargins xmlns=" http://tempuri.org/" />
</soap:Body>

Response: HTTP/1.1 200 OK
<soap:Body>
<GetMarginsResponse xmlns=" http://tempuri.org/">
<GetMarginsResult>
<string>string</string>
<string>string</string>
</GetMarginsResult>
</GetMarginsResponse>
</soap:Body>
--------
The service is currently in my LAN. If I call the service with the code below:
<cfinvoke
webservice = " http://oecdevel/usermanager/usermanager.asmx?wsdl"
method = "GetMargins"
returnVariable = "stGetMarginsResponse">
<cfscript>
I get response: org.tempuri.ArrayOfString@465545dd
I have been trying to create a struct, etc but I have had not luck at all.
How can I read the response? Please help. Thanks in advance.
This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer
Aug 17, 2006 3:02 PM UTC
The response is an instance of a java object - ArrayOfString. I would suggest starting by using cfdump on it. That will list the properties and methods of your response object. I suspect you will see 2 methods, getString() and getString(int i). So, if you call stGetMarginsResponse.getString() you should have a simple string array returned that you can loop thru. Or you can call stGetMarginsResponse.getString(i), where i is 0 thru arraylen to get a specific item out of the array.

Let us know your results. Also, if you post the WSDL I will look into it further if needed.

5 replies

Correct answer
Aug 17, 2006 3:02 PM UTC
The response is an instance of a java object - ArrayOfString. I would suggest starting by using cfdump on it. That will list the properties and methods of your response object. I suspect you will see 2 methods, getString() and getString(int i). So, if you call stGetMarginsResponse.getString() you should have a simple string array returned that you can loop thru. Or you can call stGetMarginsResponse.getString(i), where i is 0 thru arraylen to get a specific item out of the array.

Let us know your results. Also, if you post the WSDL I will look into it further if needed.
Translate
Aug 18, 2006 1:16 PM UTC
Ken, thank you so much.
You are right, I do get the array length with: #ArrayLen(Result.getString())# and I get an array item with: # stGetMarginsResponse.getString(1)#.

But how do I specify a variable within the parenthesis getString(x)?

<cfloop index="x" from=1 to=12>
<!--- Try 1: Displays error --->
#stGetMarginsRespons.getString(x)#<br /> - #x#


<!--- Try 2: Concatenating displays the variable stGetMarginsRespons.getString(1) --->
<cfset xVar="stGetMarginsRespons.getString(#x#)">
#xVar#<br />

</cfloop>

THANK YOU
Translate
Aug 18, 2006 1:48 PM UTC
Your code looks basically correct:
<cfloop index="x" from=1 to=12>
<!--- Try 1: Displays error --->
#stGetMarginsRespons.getString(x)#<br /> - #x#

</cfloop>

Is it cause you dropped the 'e' on stGetMarginsRespons? Appears you are missing the last letter of the variable name.

If that is not it, post the actual error message. That is always useful.
Translate