SOAP on Rails,无法使用Savon调用WSDL方法

时间:2011-10-31 03:21:55

标签: ruby-on-rails soap wsdl savon

我想使用金融机构网络服务来“验证交易” 该方法获取两个字符串作为输入,并返回一个double作为输出。

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=)

有关如何解决这个问题的想法吗?

2 个答案:

答案 0 :(得分: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"

答案 1 :(得分: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

工作得很好! :)