我正在使用PHP版本5.4.16
当我进行SOAP调用时,它会给我错误:
SoapFault exception: [soap:Server] Server was unable to process request. ---> Object reference not set to an instance of an object. in /var/www/html/VAS_sms/index.php:24
Stack trace:
#0 /var/www/html/VAS_sms/index.php(24): SoapClient->__call('SendSMS', Array)
#1 /var/www/html/VAS_sms/index.php(24): SoapClient->SendSMS(Array)
#2 {main}
旁边是警告:
警告:具有非复合名称'SoapClient'的use语句没有 第2行的C:\ wamp \ www \ VAS_sms \ index.php中的效果
我失去了理智让它运行..
这是我的代码:
<?php
use SoapClient;
ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
$wsdl_path = "https://smsvas.vlserv.com/KannelSending/service.asmx?WSDL";
$client = new SoapClient($wsdl_path, array('trace' => 1));
$userName = "username";
$Password = "password";
$SMSText = "text";
$SMSLang = "e";
$SMSSender = "sender";
$SMSReceiver = "01xxxxxxxxx";
try {
echo "<pre>\n";
$result = $client->SendSMS(array(
"Username" => $userName,
"Password" => $Password,
"SMSText" => $SMSText,
"SMSLang" => $SMSLang,
"SMSSender" => $SMSSender,
"SMSReceiver" => $SMSReceiver));
function objectToArray($d){
if (is_object($d)){
$d = get_object_vars($d);
}
if (is_array($d)){
return array_map(__FUNCTION__, $d);
}
else {return $d;}
}
$response_arr = objectToArray($result);
echo "return_code= " . str_replace(";", "", $response_arr);
echo "\n</pre>";
}
catch (SoapFault $exception) {
echo $exception;
}
?>
有什么建议吗?
方面问:是否有任何文件缺失我应该包含而不是use SoapClient;
?!
提前致谢
编辑1
在文档文件中:
<?php
use SoapClient;
$client = new SoapClient("https://smsvas.vlserv.com/KannelSending/service.asmx");
$userName = "username";
$Password = "password";
$SMSText = "text";
$SMSLang = "e";
$SMSSender = "sender";
$SMSReceiver = "01xxxxxxxxx";
$result = $client->SendSMS(array(
"Username" => $userName,
"Password" => $Password,
"SMSText" => $SMSText,
"SMSLang" => $SMSLang,
"SMSSender" => $SMSSender,
"SMSReceiver" => $SMSReceiver));
$response_arr = objectToArray($result);
echo "return_code= " . str_replace(";", "", $response_arr);
function objectToArray($d)
{
if (is_object($d))
{$d = get_object_vars($d);}
if (is_array($d))
{return array_map(__FUNCTION__, $d);}
else {return $d;}
}
?>
注意:我们使用PHP SoapClient来调用API Web服务,所以你 需要启用libxml PHP扩展。 因为它的反应是 对象(不是字符串)所以你需要使用它将它转换为数组 objectToArray函数。