我正在尝试使用此代码连接到此Web服务。
$url = 'https://www.dataaccess.com/webservicesserver/numberconversion.wso?WSDL';
$client = new SoapClient($url);
$xmlr = new SimpleXMLElement("<NumberToWords></NumberToWords>");
$xmlr->addChild('ubiNum', 10);
$params = new stdClass();
$params->xml = $xmlr->asXML();
$result = new SimpleXMLElement($client->NumberToWords($params)->NumberToWords->any);
$r = current($result->xpath('/webservicesserver/numberconversion'));
// if ( $r == '-1' ) {
// echo 'Fallo: '.$result->xpath('/Customers/ErrorMessage')[0];
//} else {
// echo 'Exito!';
//}
echo PHP_EOL;
//another code that gets the same kind of error
$client = new SoapClient("https://www.dataaccess.com/webservicesserver/numberconversion.wso?WSDL");
print($client->NumberToWords(1));
,并且两次都出现这种错误。
致命错误:未捕获的SoapFault异常:[客户端] SOAP错误: 编码:对象中没有'ubiNum'属性 C:\ xampp \ htdocs \ dashboard \ SoapTest3.php:33堆栈跟踪:#0 C:\ xampp \ htdocs \ dashboard \ SoapTest3.php(33): SoapClient-> __ call('NumberToWords',Array)#1 {main}被抛出 C:\ xampp \ htdocs \ dashboard \ SoapTest3.php,第33行
编辑: 这段代码似乎可以满足我的要求。
<?php
$servicio="https://www.dataaccess.com/webservicesserver/numberconversion.wso?WSDL"; //url del servicio
$parametros=array(); //parametros de la llamada
$parametros['ubiNum']=23;
$client = new SoapClient($servicio, $parametros);
$result = $client->NumberToWords($parametros);//
var_dump( $result);
echo $result->NumberToWordsResult;