2013-01-24 11 views
6

Ich benutze savon version 2 (mit Ruby on Rails) um einen Webservice aufzurufen und ich muss einige zusätzliche Namespaces in meinen Envelope einfügen. Etwas wie:Rails - Savon setzt mehrere Namespaces

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

Mein aktueller Code ist:

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

... aber in meinem Wunsch der Savon setzt nur den letzten 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/"> 

ich keine Unterlagen gefunden haben darüber auf Savon Git project.

Hat jemand eine Umgehungsmöglichkeit für dieses Problem?

PS- Ich überprüfe auch, dass eine mögliche Lösung ist, alle XML-Anfrage (der Umschlag) zu verlangen, aber ... nun ... ist zu viel wie ein Hack.

Wenn dies nicht möglich ist, und es gibt andere gute Juwelen, dies zu tun, bitte sagen Sie mir =)

Antwort

10

Ich fand das nicht möglich ist (bis jetzt) ​​mehr Namespaces auf Version 2 von Savon einzustellen.

Vorerst i wandern meine Anwendung auf Savon Version 1 und es hat funktioniert =)

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 

Weitere Informationen here und here.

Diese Frage auf der nächsten Version auf Savon 2 mit diesem Code gelöst werden:

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

Seit Savon 2.1.0, dann ist es möglich, die namespaces Schlüssel mit einem Hash von Namespace-Definitionen zu tun Einstellung:

Savon.client({ 
    ... 
    namespaces: { 
    'xmlns:first' => 'http://someURL.pt/Test1', 
    'xmlns:second' => 'http://someURL.pt/Test2', 
    'xmlns:nth' => 'http://someURL.pt/TestN' 
    } 
}) 
Verwandte Themen