2010-02-05 74 views
4

大家好我试图使用SSL,客户端证书和基本身份验证向受保护的wsdl和web服务发出一个简单请求。使用SSL基本认证和客户端证书帮助SOAP响应

下面的代码

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> 
+0

不是一个答案,但我不能评论,我很好奇,为什么你必须降级红宝石到1.8.7?我有一个类似的问题获得自签名证书。 – r3nrut 2010-12-16 16:39:52

回答

3

尝试打印出来以下 - 或只是在irb中做到这一点

client.wsdl.soap_actions 

我猜你会看到AddCustomer不是一个。它可能已被改为add_customer之类的东西。

+0

你是对的,但现在从AddCustomer更改为add_customer后,我收到以下错误: savon/soap.rb:164:in input_array':undefined method'map'for“addCustomer”:String(NoMethodError) – acemutha 2010-02-09 14:45:42

+0

好的解决! !至少有3个问题: - 我的红宝石是1.9.1,现在是1.8.7 - WSDL中的终点是错 - 我不得不用@inorder发送键和值的正确顺序。 感谢您的时间 – acemutha 2010-02-09 16:54:37