【发布时间】:2016-07-24 16:02:40
【问题描述】:
我正在处理一个需要使用 SOAP api 的项目...并且非常喜欢 Savon 解决此问题的外观。这是我第一次在代码学院教程之外使用 API...
长话短说,无论我做什么...第三方 API 一直在说错误的 api 密钥...因为他们的错误报告很弱。我在这里拥有所有这些的代码 - 但在学习安装 gem 以记录传出的 http 请求后将其删除。在这样做时,我已经找到了问题的根源......并且可以使用一些指导。
简而言之 - Savon 生成的传出 XML 与 SOAPUI 生成的不同。
使用 SOAPUI(我们想要什么...)
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sec="http://secure.treasury.exchange/">
<soapenv:Header/>
<soapenv:Body>
<sec:GetAccountBalance soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<GetAccountBalanceRequest xsi:type="sec:GetAccountBalanceRequest">
<!--You may enter the following 2 items in any order-->
<ApiKey xsi:type="xsd:string">xxx</ApiKey>
<AccountNumber xsi:type="xsd:string">123</AccountNumber>
</GetAccountBalanceRequest>
</sec:GetAccountBalance>
</soapenv:Body>
</soapenv:Envelope>
这就是 Savon 正在生成的内容
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tns="http://secure.treasury.exchange/"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<tns:GetAccountBalance>
<apiKey>xxx</apiKey>
<accountNumber>123</accountNumber>
</tns:GetAccountBalance>
</env:Body>
</env:Envelope>
我假设我需要在配置中设置一些变量以将 Savon 与 SOAP UI 正在做的事情联系起来......
有什么建议吗?
更新:找到肮脏的解决方案。
https://www.reddit.com/r/ruby/comments/289wfn/soap_issues_with_savon/
简而言之,您可以定义一个 xml: 变量...您可以使用它来定义您希望 savon 请求的确切 xml。它看起来并不漂亮,但至少它现在可以工作。
我会留意更好的解决方案。
【问题讨论】:
标签: ruby-on-rails ruby xml api savon