PHP SOAP 调用客户端函数
Posted
技术标签:
【中文标题】PHP SOAP 调用客户端函数【英文标题】:PHP SOAP Call Client Functions 【发布时间】:2016-06-20 13:32:33 【问题描述】:我需要调用没有库的soap客户端函数(nusoap、zendframework、laravel) Web Service from Here(http://www.service-repository.com/operation/show?operation=GetCitiesByCountry&portType=GlobalWeatherSoap&id=4),但我需要帮助。我尝试调用客户端肥皂函数,但收到此错误:
致命错误:未捕获的 SoapFault 异常:[soap:Server] System.Web.Services.Protocols.SoapException:服务器无法处理请求。 ---> System.Data.SqlClient.SqlException:过程或函数“getWCity”需要参数“@CountryName”,但未提供该参数。在 WebServicex.GlobalWeather.GetCitiesByCountry(String CountryName) --- 内部异常堆栈跟踪结束 --- 在 /Applications/XAMPP/xamppfiles/htdocs/php-soap/soap/Client.php:41 堆栈跟踪:#0 /Applications /XAMPP/xamppfiles/htdocs/php-soap/soap/Client.php(41): SoapClient->__soapCall('GetCitiesByCoun...', Array) #1 main 在 /Applications/XAMPP/xamppfiles/htdocs/ 中抛出第 41 行的 php-soap/soap/Client.php
这是我的服务器类:
class ServerSoap extends SoapServer
public function __construct()
$params= array('encoding'=>'UTF-8','soap_version' => SOAP_1_2);
$wsdl="http://www.webservicex.com/globalweather.asmx?WSDL";
parent::SoapServer($wsdl,$params);
parent::addFunction("GetCitiesByCountry");
public function fault ($code, $string, $actor = null, $details = null, $name = null)
throw new SoapFault($code, $string, $actor, $details, $name);
$server = new ServerSoap();
$server->setClass('ServerSoap');
$server->handle();
这是我的客户端类:
class Client extends SoapClient
public function __construct()
$wsdl_client="http://localhost:8080/php-soap/soap/ServerSoap.php?wsdl";
$params_client = array(
'trace' => TRUE,
'wsdl'=>TRUE,
'debug'=>TRUE,
'cache_wsdl'=>WSDL_CACHE_BOTH
);
parent::__construct($wsdl_client,$params_client);
$this->server = new SoapServer($wsdl_client,$params_client);
public function disableClient()
$old_location = $this->instance->__setLocation();
return $old_location;
$country="Spain";
$client = new Client();
$client->__soapCall("GetCitiesByCountry", array("CountryName"=>$country));
echo $client->__getLastResponse();
请帮帮我。
【问题讨论】:
【参考方案1】:按照提供的wsdl,我认为正确的调用方式是
$client->GetCitiesByCountry([
'GetCitiesByCountry' => [
'CountryName' => $country
]
];
一个是GetCitiesByCountry
SOAP 操作,另一个是GetCitiesByCountry
元素。
【讨论】:
以上是关于PHP SOAP 调用客户端函数的主要内容,如果未能解决你的问题,请参考以下文章