Rails - Savon设置了多个名称空间

JMa*_*ues 8 soap namespaces ruby-on-rails savon

我正在使用savon版本2(使用Ruby on Rails)来调用web服务,我需要为我的Envelope注入一些额外的命名空间.就像是:

<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"
Run Code Online (Sandbox Code Playgroud)

我目前的代码是:

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... )
Run Code Online (Sandbox Code Playgroud)

...但在我的请求中,Savon只放置最后一个命名空间

<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/">
Run Code Online (Sandbox Code Playgroud)

我没有在Savon Git项目上找到任何关于此的文档.

有没有人有这个问题的解决方法?

PS-我还检查一个可能的解决方案是将所有xml请求(信封)设置为请求但是......嗯...太像黑客了.

如果这是不可能的并且还有其他好的宝石可以做到这一点,请告诉我=)

JMa*_*ues 10

我发现(现在)在Savon的第2版上设置多个名称空间是不可能的.

现在我在Savon版本1上迁移我的应用程序,它工作=)

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
Run Code Online (Sandbox Code Playgroud)

更多信息在这里这里.

这个问题将通过以下代码在Savon 2的下一个版本中得到解决:

namespaces(
   "xmlns:first" => "http://someURL.pt/Test1",
   "xmlns:two"   => "http://someURL.pt/Testweewqwqeewq"
)
Run Code Online (Sandbox Code Playgroud)


Cri*_*nça 7

Savon 2.1.0开始,可以通过namespaces使用命名空间定义的哈希设置密钥来完成:

Savon.client({
  ...
  namespaces: {
    'xmlns:first' => 'http://someURL.pt/Test1',
    'xmlns:second' => 'http://someURL.pt/Test2',
    'xmlns:nth' => 'http://someURL.pt/TestN'
  }
})
Run Code Online (Sandbox Code Playgroud)