doudongdang4483 2016-03-07 04:43
浏览 51
已采纳

PHP SOAP调用客户端函数

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.

</div>
  • 写回答

1条回答 默认 最新

  • doufu8588 2016-07-19 16:28
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 xshell无法连接提示ssh服务器拒绝密码
  • ¥15 AT89C52单片机C语言关于串口通信的位操作
  • ¥20 需要步骤截图(标签-服务器|关键词-map)
  • ¥50 gki vendor hook
  • ¥15 灰狼算法和蚁群算法如何结合
  • ¥15 这是一个利用ESP32自带按键和LED控制的录像代码,编译过程出现问题,请解决并且指出错误,指导如何处理 ,协助完成代码并上传代码
  • ¥20 stm32f103,hal库 hal_usart_receive函数接收不到数据。
  • ¥20 求结果和代码,sas利用OPTEX程序和D-efficiency生成正交集
  • ¥50 adb连接不到手机是怎么回事?
  • ¥20 抓取数据时发生错误: get_mooncake_data() missing 1 required positional argument: 'driver'的问题,怎么改出正确的爬虫代码?