我有一些用于访问安全 Web 服务的 PHP 示例(见下文)。我正在尝试使用 Savon 访问网络服务。首先,我试过:
>> 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 凭据访问 Web 服务,如下所示:
>> 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);