简体   繁体   中英

PHP SOAP Call Client Functions

I need call soap client functions without libraries(nusoap , zendframework , laravel) I only should to work with php native because is a requiriment for the another proyect more important on the future so for the moment I just practice with a simple public Web Service from Here( http://www.service-repository.com/operation/show?operation=GetCitiesByCountry&portType=GlobalWeatherSoap&id=4 ) , but I need Help.I try to call client soap functions but I recive this error:

Fatal error: Uncaught SoapFault exception: [soap:Server] System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Data.SqlClient.SqlException: Procedure or function 'getWCity' expects parameter '@CountryName', which was not supplied. at WebServicex.GlobalWeather.GetCitiesByCountry(String CountryName) --- End of inner exception stack trace --- in /Applications/XAMPP/xamppfiles/htdocs/php-soap/soap/Client.php:41 Stack trace: #0 /Applications/XAMPP/xamppfiles/htdocs/php-soap/soap/Client.php(41): SoapClient->__soapCall('GetCitiesByCoun...', Array) #1 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/php-soap/soap/Client.php on line 41

This is my server Class:

 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(); 

This is my client class:

 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(); 

Please Help me.

Following the wsdl provided, I think the right way to call it is

$client->GetCitiesByCountry([
    'GetCitiesByCountry' => [
        'CountryName' => $country
    ]
];

One thing is the GetCitiesByCountry SOAP action, and another is the GetCitiesByCountry element.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM