Rails上的SOAP,不能使用Savon用WSDL调用方法



我想使用一个金融机构的web服务来"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=)

关于如何解决这个问题有什么想法吗?

由于我没有有效的信息来实际尝试此操作,因此我所能做的就是返回HTTP 400而不是其他列出的SOAP错误或来自服务的500响应。

Savon只设置了基本的设置:

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

我发现不同之处在于为特定的请求指定了名称空间。为"urn:Foo"更改:wsdl输出

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

我使用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

它工作得很好!:)

最新更新