• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Web Services - Handling complex type response

New Here ,
Aug 16, 2006 Aug 16, 2006

Copy link to clipboard

Copied

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.
TOPICS
Advanced techniques

Views

657

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Aug 17, 2006 Aug 17, 2006
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 you...

Votes

Translate

Translate
Enthusiast ,
Aug 17, 2006 Aug 17, 2006

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 18, 2006 Aug 18, 2006

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 18, 2006 Aug 18, 2006

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 18, 2006 Aug 18, 2006

Copy link to clipboard

Copied

Ken,

I have it working just fine with the code below:

<cfinvoke
webservice = " http://sim.openecry.com/usermanager/usermanager.asmx?wsdl"
method = "GetMargins"
returnVariable = "Result">

<cfdump var="#Result#">
<cfoutput>
<cfset xArrayItems=#Result.getString()#>
<cfset xLen=ArrayLen(Result.getString())>
<cfloop index="x" from=1 to="#xLen#">
#x# - #xArrayItems#<br />
</cfloop>
</cfoutput>

I can refer to the array item by first assigning the array from property method to a regular variable. I am not sure this is the proper way to do it but it works.
Thanks a lot for you help I appreciate it very much.

Davide Formica

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 18, 2006 Aug 18, 2006

Copy link to clipboard

Copied

LATEST
It look fine. If your previous error was an undefined variable it was due to the mispelling of your previous return variable.

Your current code looks, OK but not very 'nice'. You do not need most of your pound signs. See attached:

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation