首页 > 解决方案 > Savon 不使用参数填充 XML

问题描述

系统:

ruby 2.7.3p183(2021-04-05 修订版 6847ee089d)[x86_64-darwin20]

萨翁2.12.1

我的客户端设置如下所示

def client
  @client ||= Savon.client do
    log true
    wsdl BASE_URL
    pretty_print_xml true
    ssl_verify_mode :none
  end
end

当我查看日志以验证 Savon 生成的 XML 时,我注意到缺少一些参数。在这种情况下,它是customerID

要求:

client.call(:authenticate, message: { customerID: 123456, passphrase: 'qwertyasdfg' })

日志:

I, [2021-07-06T13:06:29.621011 #39758]  INFO -- : SOAP request: *filtered*
I, [2021-07-06T13:06:29.621067 #39758]  INFO -- : SOAPAction: "*filtered*", Content-Type: text/xml;charset=UTF-8, Content-Length: 569
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="*filtered*" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
  <env:Body>
    <authenticate>
      <customerID xsi:type="xsd:nonNegativeInteger"/>
      <passphrase xsi:type="xsd:normalizedString">qwertyasdfg</passphrase>
      <sandbox xsi:type="xsd:boolean"/>
      <locale xsi:type="tns:Locale"/>
      <demo xsi:type="xsd:boolean"/>
    </authenticate>
  </env:Body>
</env:Envelope>

D, [2021-07-06T13:06:29.621467 #39758] DEBUG -- : HTTPI /none POST request to *filtered* (httpclient)
I, [2021-07-06T13:06:29.994037 #39758]  INFO -- : SOAP response (status 400)
D, [2021-07-06T13:06:29.994316 #39758] DEBUG -- : <?xml version="1.0" encoding="UTF-8"?>

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
  <SOAP-ENV:Body>
    <SOAP-ENV:Fault>
      <faultcode>SOAP-ENV:Client</faultcode>
      <faultstring>Failed to authenticate.</faultstring>
    </SOAP-ENV:Fault>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

您可以在此处看到customerID参数未填充值123456。我的设置中是否缺少任何内容?这不是第一个案例。它也发生在其他请求上,所以我必须单独构建 XML 并使用带有原始 XML 的 API 进行操作

标签: ruby-on-railsrubysoapsavon

解决方案


推荐阅读