由于我没有实际尝试此操作的有效信息,我所能做的就是返回 HTTP 400,而不是其他列出的 SOAP 错误或来自服务的 500 响应。
Savon 的设置只有基础:
client = Savon::Client.new do
wsdl.document = "https://acquirer.sb24.com/ref-payment/ws/ReferencePayment?WSDL"
end
我发现的不同之处在于为特定请求指定了命名空间。将 :wsdl 更改为“urn:Foo”。
[26] pry(main)> client.request "urn:Foo", :verify_transaction do
[26] pry(main)* soap.body = { "RefNum" => "1", "MerchantID" => "1" }
[26] pry(main)* end
调试请求的输出:
D, [2011-10-31T09:05:17.202044 #1784] DEBUG -- : SOAP request: https://acquirer.sb24.com/ref-payment/ws/ReferencePayment
D, [2011-10-31T09:05:17.202314 #1784] DEBUG -- : SOAPAction: "verifyTransaction", Content-Type: text/xml;charset=UTF-8, Content-Length: 322
D, [2011-10-31T09:05:17.202414 #1784] DEBUG -- : <?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:urn:Foo="urn:Foo" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ins0="urn:Foo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Body><urn:Foo:verifyTransaction><MerchantID>1</MerchantID><RefNum>1</RefNum></urn:Foo:verifyTransaction></env:Body></env:Envelope>
D, [2011-10-31T09:05:17.202574 #1784] DEBUG -- : HTTPI executes HTTP POST using the httpclient adapter
D, [2011-10-31T09:05:18.780446 #1784] DEBUG -- : SOAP response (status 400):
D, [2011-10-31T09:05:18.780669 #1784] DEBUG -- :
Savon::HTTP::Error:
from /usr/local/rvm/gems/ruby-1.8.7-p334/gems/savon-0.9.7/lib/savon/soap/response.rb:100:in `raise_errors'
更长的解释
这就是我想出上述格式的方式。
命名空间对于某些服务可能很重要。仔细查看 wsdl,这是实际使用的操作,因为端口引用是“PaymentIF”端口:
<message name="PaymentIF_verifyTransaction">
<part name="String_1" type="xsd:string"/>
<part name="String_2" type="xsd:string"/>
</message>
在端口定义中,实际消息被称为“tns:PaymentIF_verifyTransaction”:
<portType name="PaymentIF">
...
<operation name="verifyTransaction" parameterOrder="String_1 String_2">
<input message="tns:PaymentIF_verifyTransaction"/>
<output message="tns:PaymentIF_verifyTransactionResponse"/>
</operation>
...
</portType>
所以再次回顾顶部,“tns”命名空间是:
xmlns:tns="urn:Foo"