Savon.rb and sequences

As I wrote in my last post, I’ve recently learned it is important to be able to show what you’ve been doing. So I’m trying to increase the posts on a number of small problems I find in my daily job, and in my hobby projects. This one appeared in my daily job.

I was developing a small interface between two applications via a SOAP web service. Actually, we are using Redmine for development, and Remedy for the whole organization, and we didn’t want to fill the information twice.

I was using Savon.rb for creating a client in Redmine that would invoke a SOAP web service in Remedy. The code was something like this:

  response=client.request "Resolver" do
    soap.header={:AuthenticationInfo=>{
          :userName=>ws_user,
          :password=>ws_pwd,
    }
    soap.body = {
        "Status"=>"Resolved",
        "Resolution"=> message ,
        "Status_Reason"=>"Client Action Required",
        "Incident_Number"=>code,
        "Status_Reason2"=>"Client Action Required",
        "AssigneeLoginID"=>user,
    }
  end

However, I was getting a SOAP error

ARERR [8962] Unexpected element encountered in the input XML document

The problem lies in Ruby hashes not preserving the order and Savon sending XML sequences in incorrect order. I just updated the call to something like this

  response=client.request "Resolver" do
    soap.header={:AuthenticationInfo=>{
          :userName=>ws_user,
          :password=>ws_pwd,
          :order! => [:userName, :password]
    }
    soap.body = {
        "Status"=>"Resolved",
        "Resolution"=>message,
        "Status_Reason"=>"Client Action Required",
        "Incident_Number"=>code,
        "Status_Reason2"=>"Client Action Required",
        "AssigneeLoginID"=>user,
        :order! => ["Status", "Resolution", "Status_Reason","Incident_Number", "Status_Reason2", "AssigneeLoginID"]
    }
  end

and it solved the issue. I expected Savon to take care of this, but anyway, I understand this is solved in Ruby 1.9x.



First published here