Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails - Savon set multiple namespaces

I'm using savon version 2 (with Ruby on Rails )to invoke a webservice and i need to inject some additional namespaces to my Envelope. Something like:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:add="http://schemas.xmlsoap.org/ws/2003/03/addressing" 
xmlns:newNamespace1="http://someURL.pt/Test1" 
xmlns:newNamespace2="http://someURL.pt/Test2" 
xmlns:newNamespace3="http://someURL.pt/Test3"

My current code is:

client = Savon.client do
        wsdl "https://someValidURL?wsdl"

        namespace "http://someURL.pt/Test1" 
        namespace "http://someURL.pt/Test2" 
        namespace "http://someURL.pt/Test3"
end

response = client.call( ...the webservice call... )

...but in my request the Savon only puts the last namespace

<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsns="http://someURL.pt/Test3" 
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">

I didn't find any documentation about this on Savon Git project.

Does anyone have a workaround for this problem??

PS- I also check that one possible solution is to set all the xml request (the envelope) to request but ... well... is too much like a hack.

If this is not possible and there's other good gem to do this, please tell me =)

like image 619
JMarques Avatar asked Jan 24 '13 12:01

JMarques


2 Answers

I found that is not possible (for now) to set multiple namespaces on version 2 of Savon.

For now i migrate my application on Savon version 1 and it worked =)

begin
    client = Savon::Client.new do
        wsdl.document = "https://someURL?wsdl"
    end

  @response = client.request :service do
       soap.namespaces["xmlns:test1"]  = "http:/someURLtest1"
       soap.namespaces["xmlns:test2"]  = "http:/someURLtest2" 

       soap.body = { #... the message....
          :"test1:something" => {}, 
          :"test2:something1" => {}
                   }
   end


  rescue Savon::Error => error
     log error.to_s
  end

More information here and here.

This question will be solved on the next version on Savon 2 with this code:

namespaces(
   "xmlns:first" => "http://someURL.pt/Test1",
   "xmlns:two"   => "http://someURL.pt/Testweewqwqeewq"
)
like image 161
JMarques Avatar answered Nov 03 '22 08:11

JMarques


Since Savon 2.1.0, it's possible to be done by setting the namespaces key with a hash of namespace definitions:

Savon.client({
  ...
  namespaces: {
    'xmlns:first' => 'http://someURL.pt/Test1',
    'xmlns:second' => 'http://someURL.pt/Test2',
    'xmlns:nth' => 'http://someURL.pt/TestN'
  }
})
like image 26
Cristiano Mendonça Avatar answered Nov 03 '22 09:11

Cristiano Mendonça