0

我想使用金融机构的网络服务来“verifyTransaction”该方法获取两个字符串作为输入并返回一个双精度作为输出。

double verifyTransaction (
String      RefNum, 
String      MerchantID
)

我在 rails 3.1 中使用 Savon 来调用该方法。

client = Savon::Client.new do |wsdl|
    wsdl.document = "https://acquirer.sb24.com/ref-payment/ws/ReferencePayment?WSDL"
end

response = client.request :wsdl, "verifyTransaction" do
  soap.body ={"RefNum" => "ReferenceNumber", "MerchantID" => "MymerchantId"}
end

但我得到了这个错误:

Savon::SOAP::Fault ((env:Client) caught exception while handling request: unexpected encoding style: expected=http://schemas.xmlsoap.org/soap/encoding/, actual=)

关于如何解决这个问题的任何想法?

4

2 回答 2

0

由于我没有实际尝试此操作的有效信息,我所能做的就是返回 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"
于 2011-10-31T14:16:38.170 回答
0

我通过使用 SoapUI 解决了这个问题。

我在 SoapUI 中打开了 WSDL,生成了一个示例请求并将其复制/粘贴到 Savon 中,如下所示:

client = Savon::Client.new do |wsdl|
    wsdl.document = "https://acquirer.sb24.com/ref-payment/ws/ReferencePayment?WSDL"
end

response = client.request "verifyTransaction" do
  soap.xml = 'XML will be here'
end

效果很好!:)

于 2011-11-02T17:28:10.077 回答