本文介绍了Rails-Savon设置了多个命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 savon版本2 (与Ruby on Rails一起)来调用Web服务,我需要为我的信封注入一些其他名称空间.像这样:

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"

我当前的代码是:

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... )

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

...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/">

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

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

有人可以解决此问题吗?

Does anyone have a workaround for this problem??

PS-我还检查了一种可能的解决方案,就是将所有xml请求(信封)设置为要请求,但是……好吧……太像黑客了.

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 =)

推荐答案

我发现暂时无法在Savon版本2上设置多个名称空间.

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

目前,我在Savon版本1上迁移了我的应用程序,并且它可以工作=)

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

更多信息此处此处.

此问题将在Savon 2的下一版本中使用以下代码解决:

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"
)

这篇关于Rails-Savon设置了多个命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 00:02