0

有人可以转换这个:

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

现在使用 Soap gem SAVON,如何以 client.request 方法可以处理的正确语法编写它?

我试过这个:

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

但我收到 HTTP 400 错误。

有什么建议吗?

4

1 回答 1

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
于 2012-10-17T04:07:51.423 回答