2012-10-16 73 views
0

有人可以將此轉換:轉換此XML請求到合適的薩翁要求

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://test.org/" xmlns:hon="http://schemas.datacontract.org/2004/07/TEST.RVU.Entity"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <tem:Authenticate> 
     <!--Optional:--> 
     <tem:authenticationDet> 
      <!--Optional:--> 
      <hon:AccountType>0</hon:AccountType> 
      <!--Optional:--> 
      <hon:Password>bacon</hon:Password> 
      <!--Optional:--> 
      <hon:UserName>smith</hon:UserName> 
     </tem:authenticationDet> 
     </tem:Authenticate> 
    </soapenv:Body> 
</soapenv:Envelope> 

現在用肥皂寶石SAVON,我怎麼能寫在正確的語法,該client.request方法可以處理呢?

我嘗試這樣做:

client.request :tem, :authenticate, body: { "authenticationDet" => { "AccountType" => 0, "Password" => "bacon", "UserName" => "smith"}} 

但我得到一個HTTP 400錯誤。

有什麼建議嗎?

回答

0

您需要設置額外的命名空間。 SOAP操作必須用引號與您的匹配。

該腳本可能是這樣的:

#!ruby 

require "savon" 

Savon.configure do |c| 
    c.pretty_print_xml = true 
    c.env_namespace = :soapenv 
end 

client = Savon::Client.new do 
    wsdl.namespace = "http://test.org" 
    wsdl.endpoint = "http://localhost" 
end 

resp = client.request :tem, 'Authenticate' do 
    soap.namespaces["xmlns:hon"] = "http://schemas.datacontract.org/2004/08/TEST.RVU.Entity" 
    soap.body = { "tem:authenticationDet" => 
       { "hon:AccountType" => 0, 
        "hon:Password" => "bacon", 
        "hon:UserName" => "smith" } 
       } 
end