Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8854261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:50:33+00:00 2026-06-14T13:50:33+00:00

I am attempting to use Savon to communicate with a legacy web service using

  • 0

I am attempting to use Savon to communicate with a legacy web service using SOAP. I am having an issue with regards to how Savon constructs a hash out of the response envelope.

client = Savon.client("http://my-service-endpoint/?wsdl")

response = client.request :my_soap_operation do
  soap.body do |xml|
    xml.in("test")
  end
end

response.to_hash[:my_soap_operation_response][:out].each do |a|
   puts "Return element: #{a}"
   puts "Name #{a[:name]}"
   puts "Type #{a[:type]}"
   puts "Code #{a[:code]}"
end

end

If the SOAP response contains more than 1 ‘out’ element, such as this:

<mySoapOperationResponse>
  <out>
   <code>C1947944</code>
   <name>Use</name>
   <type>type 1</type>
 </out>
 <out>
   <code>C1947946</code>
   <name>name 2</name>
   <type>type 2</type>
 </out>
 <out>
   <code>C1947947</code>
   <name>name 2</name>
   <type>type 3</type>
 </out>
</mySoapOperationResponse>

The output is as expected:

Return element: {:code=>"C1947944", :name=>"Use", :type=>"type 1"}
Name Use
Type type 1
Code C1947944
Return element: {:code=>"C1947946", :name=>"name 2", :type=>"type 2"}
Name name 2
Type type 2
Code C1947946
Return element: {:code=>"C1947947", :name=>"name 2", :type=>"type 3"}
Name name 2
Type type 3
Code C1947947

However, if the SOAP response only contains a single ‘out’ element, such as this:

<mySoapOperationResponse>
     <out>
        <code>C1947944</code>
        <name>name 1</name>
        <type>type 1</type>
     </out>
</mySoapOperationResponse>

I see this in the console

Return element: [:code, "C1947944"]

… and then I get the error message

can't convert Symbol into Integer

It would appear as though the :name and :type elements are not present in the SOAP response, however I can see them via the response XML message.

I am using Savon v1.2.0.

Addendum

I added the following code to try to further debug the issue:

 response = client.request :my_soap_operation do
  soap.body do |xml|
    xml.in("test")
  end
 end

pp response.to_hash

response.to_hash[:my_soap_operation_response][:out].each do |a|
   pp a
   puts "Return element: #{a}"
   puts "Name #{a[:name]}"
   puts "Type #{a[:type]}"
   puts "Code #{a[:code]}"

And I can see the elements being pretty-printed in the response hash. Here is a snapshot of the console:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
    <mySoapOperationResponse>
        <out>
            <code>C1947944</code>
            <name>name 1</name>
            <type>type 1</type>
        </out>
    </mySoapOperationResponse>
 </soapenv:Body>
</soapenv:Envelope>

{:my_soap_operation_response=>
    {:out=>{:code=>"C1947944", :name=>"name 1", :type=>"type 1"},
        :@xmlns=>"http://namespace.removed.com/"}}

[:code, "C1947944"]
Return element: [:code, "C1947944"]

However it seems like inside the .each loop (looping over each ‘out’ element), only the first element can be accessed?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:50:34+00:00Added an answer on June 14, 2026 at 1:50 pm

    I think the issue is, that Savon doesn’t return an Array in the second case. You need to check
    whether [:out] is an Array or a single value and act accordingly. What I did was I wrapped the single value into an Array of one element to keep my program structure simple.

    def wrapped_soap_call
      # prepare Savon::Client to your liking
      client = Savon::Client.new do
        # your stuff here
      end
    
      # call the SOAP WS
      result = client.request :wsdl, :function do
        # your stuff here
      end
    
      list = result.to_hash[:response][:out]
      # if there was only one item list is not an array!
      if list.is_a? Array
        return list
      else
        return Array.new << list
      end
    end
    

    That works for me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Attempting to use XStream's JavaBeanConverter and running into an issue. Most likely I'm missng
I am attempting to use the following code to search a database using words
I am attempting to use an Intent Service to run in the background to
I'm attempting to use a 3rd party service that uses OAuth 1.0a and requires
I am attempting to use a web grid helper in conjunction with a generic
Attempting to use the data series from this example no longer passes the JSONLint
When attempting to use HttpWebRequest to retrieve a page from my dev server, I
Im attempting to use a C++ extension for Python called PySndObj. and getting an
In attempting to use std::select1st from <functional> in a VS2008 project I found that
Im attempting to use websockets for a project. It needs to use the ipad,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.