9

私はsavonバージョン2(Ruby on Railsを使用)を使用してWebサービスを呼び出しており、エンベロープにいくつかの追加の名前空間を挿入する必要があります。何かのようなもの:

<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は最後の名前空間のみを配置します

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

SavonGitプロジェクトでこれに関するドキュメントは見つかりませんでした。

誰かがこの問題の回避策を持っていますか?

PS-私はまた、1つの可能な解決策がすべてのxmlリクエスト(エンベロープ)をリクエストに設定することであることを確認しますが...まあ...ハックに非常に似ています。

これが不可能で、これを行うための他の良い宝石がある場合は、教えてください=)

4

2 に答える 2

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

ここここの詳細情報。

この質問は、Savon2の次のバージョンで次のコードを使用して解決されます。

namespaces(
   "xmlns:first" => "http://someURL.pt/Test1",
   "xmlns:two"   => "http://someURL.pt/Testweewqwqeewq"
)
于 2013-01-25T16:11:21.110 に答える
8

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'
  }
})
于 2016-06-08T18:09:36.057 に答える