2013-01-24 47 views
6

我使用savon version 2(使用Ruby on Rails)來調用Web服務,我需要向我的Envelope注入一些額外的命名空間。喜歡的東西:Rails - Savon設置多個命名空間

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

...但在我的請求,薩翁只把最後一個命名空間

<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 project

有沒有人有這個問題的解決方法?

PS-我也檢查一種可能的解決方案是設置所有的xml請求(信封)請求,但...呃...太像一個黑客。

如果這是不可能的,有其他好的寶石要做到這一點,請告訴我=)

回答

10

我發現這是不可能的(現在)對薩翁的第2版設置了多個命名空間。

現在我在我的應用程序移植在薩翁版本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 

更多信息herehere

這個問題將在下一版本的代碼來解決對薩翁2:

namespaces(
    "xmlns:first" => "http://someURL.pt/Test1", 
    "xmlns:two" => "http://someURL.pt/Testweewqwqeewq" 
) 
1

由於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' 
    } 
})