5 Replies Latest reply on Aug 18, 2006 7:48 AM by ksmith

    Web Services - Handling complex type response

    dformica
      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.
        • 1. Re: Web Services - Handling complex type response
          ksmith Level 1
          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.
          • 2. Re: Web Services - Handling complex type response
            dformica Level 1
            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
            • 3. Re: Web Services - Handling complex type response
              ksmith Level 1
              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.
              • 4. Re: Web Services - Handling complex type response
                dformica Level 1
                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[x]#<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
                • 5. Re: Web Services - Handling complex type response
                  ksmith Level 1
                  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: