2016-03-07 162 views
0

我需要調用SOAP客戶端功能,無需庫(的NuSOAP,zendframework,laravel)我只應與PHP自身的工作,因爲是另一個proyect一個requiriment對未來更重要的,所以目前我只從這裏一個簡單的公共Web服務(http://www.service-repository.com/operation/show?operation=GetCitiesByCountry&portType=GlobalWeatherSoap&id=4)的做法,但我需要Help.I嘗試調用客戶端SOAP的功能,但我recive這個錯誤:PHP SOAP調用客戶端函數

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

這是我的服務器類:

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元素。