如何从Ruby中的Savon调用这个安全的Web服务WSDL?

时间:2012-02-01 15:46:12

标签: ruby-on-rails ruby soap savon

我有一些有效的PHP示例(见下文),用于访问安全的Web服务。我正在尝试使用Savon访问Web服务。首先,我试过了:

>> client = Savon::Client.new("https://secure.service.com/soa/soap/?WSDL")
=> #<Savon::Client:0x114053358 @wsdl=#<Savon::WSDL:0x1140532b8 @request=#<Savon::Request:0x1140532e0 @endpoint=#<URI::HTTPS:0x114053038 URL:https://secure.service.com/soa/soap/?WSDL>, @proxy=#<URI::Generic:0x114052fc0 URL:>>>, @request=#<Savon::Request:0x1140532e0 @endpoint=#<URI::HTTPS:0x114053038 URL:https://secure.service.com/soa/soap/?WSDL>, @proxy=#<URI::Generic:0x114052fc0 URL:>>>

第一个问题,SOAP动作似乎是空的:

>> client.wsdl.soap_actions
warning: peer certificate won't be verified in this SSL session
=> []

尝试使用wsse凭据访问webservice:

>> client = Savon::Client.new do |wsdl, http|
?>   wsdl.document = "https://secure.service.com/soa/soap/?WSDL"
>>   wsdl.wsse.credentials "user", "encrypted-md5-string"
>> end

结果:

ArgumentError: wrong number of arguments (0 for 1)

可以从Ruby下面这个有用的PHP示例中获取什么来设置一些基本的Web服务请求?

PHP示例:

$foo = "+++hashkey+++";

$authUser = "user";
$authPass = "password";

$passphrase = md5($foo.$authPass.".wsdl");

echo "User: ".$authUser."<br>";
echo "Passphrase: ".$foo.$authPass.".wsdl<br>";
echo "Digest Passphrase: ".$passphrase."<br>";

$soapClient = new SoapClient( "https://secure.service.com/soa/soap/?WSDL", 
     array( "exceptions"  => true,
            "cache_wsdl" => WSDL_CACHE_NONE,
            "login" => $authUser,
            "password" => $passphrase));

$param = new stdClass();

$param->bankaccount = "1111111";
$param->bankcountry = "US";

$soaMethod = "SoaBank.getBank"; 
$soaParams = array($param);
$result = $soapClient->__soapCall($soaMethod, $soaParams);

print "<h1>Result</h1>";
print_r($result);

2 个答案:

答案 0 :(得分:2)

对于Savon 2,您可以使用:ssl_verify_mode => :none

Savon.client(:wsdl => 'https://blahService?wsdl', :ssl_verify_mode => :none)

答案 1 :(得分:1)

尝试关闭ssl验证:

    client = Savon::Client.new("http://wsdl") do
      http.auth.ssl.verify_mode = :none          
    end