使用SSL基本身份验证和客户端证书帮助SOAP响应

4

大家好,我正在尝试使用SSL、客户端证书和基本身份验证向受保护的WSDL和Web服务发出简单请求。

以下是代码:

require 'savon'

client = Savon::Client.new "https://example.com/service?wsdl"

client.request.http.ssl_client_auth(
:cert => OpenSSL::X509::Certificate.new(File.read("cert.pem")),
:key => OpenSSL::PKey::RSA.new(File.read("key.pem")),
:verify_mode => OpenSSL::SSL::VERIFY_NONE
)
client.request.basic_auth "User", "Password"

response = client.AddCustomer |soap|
soap.body = {
:Channel => 0,
:tel => '34567',
:id => '597118125',
:paymentMode => 1,
:Alias => 666,
:flag => 0
}

puts response.to_xml

使用 soapUI 进行测试的工作范围如下:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mov="http://www.example.com/services/">
<soapenv:Header/>
<soapenv:Body>
<asd:AddCustomer>
<Channel>0</idChannel>
<tel>12344</msisdn>
<id>59711</idIssuer>
<paymentMode>1</paymentMode>
<Alias>666</idAlias>
<flag>0</flagPrivacy>
</asd:AddCustomer>
</soapenv:Body>
</soapenv:Envelope>

当我运行我的代码时,我遇到了这个错误:
method_missing': undefined method `AddCustomer' for #<Savon::Client:0x8abec08>

不是答案,但我无法评论,我很好奇为什么您必须将Ruby降级到1.8.7?我遇到了类似的问题,无法使用自签名证书。 - r3nrut
1个回答

3

尝试打印以下内容 - 或只需在irb中执行即可

client.wsdl.soap_actions

我猜您会发现AddCustomer不是一个正确的命名。它可能已经被改成了类似add_customer的形式。


你是对的,但现在从AddCustomer更改为add_customer后,我收到了以下错误: savon/soap.rb:164:in input_array': undefined method `map' for "addCustomer":String (NoMethodError) - acemutha
好的,问题解决了!至少有三个问题:
  • 我的 Ruby 版本是 1.9.1,现在改为了 1.8.7
  • WSDL 中的端点错误
  • 我必须使用 @inorder 来发送正确的键和值序列。
感谢您的时间。
- acemutha

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接