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

发布于 2024-12-12 23:56:03 字数 718 浏览 0 评论 0原文

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

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

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

I want to use a financial institution webservice to "verifyTransaction"
The method gets two strings as input and return a double as output.

double verifyTransaction (
String      RefNum, 
String      MerchantID
)

I used Savon in rails 3.1 to call the method.

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

but the I got this error:

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

Any thought on how to solve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

多情出卖 2024-12-19 23:56:03

由于我没有有效的信息来实际尝试此操作,因此我所能做的就是获取 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"

Since I don't have valid information to actually try this, all I was able to do was get a HTTP 400 back instead of the other listed SOAP fault or a 500 response from the service.

Savon was setup with just the basics:

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

The difference I found was specifying the namespace for the specific request. Change the :wsdl out for "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

Debug output from the request:

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'

Longer Explanation

This is how I came up with the format above.

The namespacing can be important for some services. Looking at the wsdl carefully, this is the actual action being used since the port reference is the "PaymentIF" port:

<message name="PaymentIF_verifyTransaction">
  <part name="String_1" type="xsd:string"/>
  <part name="String_2" type="xsd:string"/>
</message>

Within the port definition the actual message is referenced as "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>

So looking back at the top again, the "tns" namespace is:

xmlns:tns="urn:Foo"
超可爱的懒熊 2024-12-19 23:56:03

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

工作正常! :)

I solved the problem by using SoapUI.

I've opened the WSDL in SoapUI, generate a sample requests and copy/paste it into Savon like this:

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

It worked fine! :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文