2013-01-24 7 views
6

Sto usando savon version 2 (con Ruby on Rails) per richiamare un webservice e ho bisogno di aggiungere alcuni spazi dei nomi aggiuntivi alla mia Busta. Qualcosa di simile:Rails - Savon imposta più domini

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

mio codice attuale è:

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

... ma nella mia richiesta Savon mette solo l'ultimo spazio dei nomi

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

non ho trovato alcuna documentazione su questo su Savon Git project.

Qualcuno ha una soluzione alternativa per questo problema?

PS- Verifico anche che una possibile soluzione è quella di impostare tutta la richiesta xml (la busta) da richiedere ma ... beh ... è troppo simile a un hack.

Se questo non è possibile e non c'è altro bene gemma per fare questo, la prego di dirmi =)

risposta

10

ho scoperto che non è possibile (per ora) per impostare più spazi dei nomi sulla versione 2 di Savon.

per ora mi migrare la mia applicazione su Savon versione 1 e ha funzionato =)

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 

Maggiori informazioni here e here.

La questione sarà risolta sulla prossima versione su Savon 2 con questo codice:

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

Dal Savon 2.1.0, è possibile essere fatto impostando la chiave namespaces con un hash di definizioni di namespace:

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