1. 程式人生 > >php soap

php soap

//https://www.youtube.com/watch?v=e_7jDqN2A-Y
tree /f
├─mysoap
│      Client.php
│      server.php
│      service.php
server.php
<?php
/**
 * Created by PhpStorm.
 * User: lichen
 * Date: 2019/1/13
 * Time: 11:48
 */
class server{
//    private $con;
    public function __construct()
    {
//        $this->con=(is_null($this->con))?self.connection:$this->con;
} // static function connetc(){ // $con=mysql_connect() // // } public function getStudentName($id_array){ return 'sam'; } } $params=array('uri'=>'127.0.0.1/mysoap/server.php'); $server=new SoapServer(NULL,$params); $server->setClass('server'); $server
->handle(); -------------------------------------------------------------------------- Client.php <?php /** * Created by PhpStorm. * User: lichen * Date: 2019/1/13 * Time: 12:06 */ class Cliet{ // private $ public function __construct() { $params=array('location' => 'http://127.0.0.1/mysoap/server.php'
, 'uri' => 'urn://127.0.0.1/mysoap/server.php', 'trace'=>1); $this->instance =new SoapClient(NULL,$params); } public function getName($id_array){ return $this->instance->__soapCall('getStudentName',$id_array); } } $client=new Cliet(); --------------------------------------------------------------------------- service.php <?php /** * Created by PhpStorm. * User: lichen * Date: 2019/1/13 * Time: 12:12 */ include './client.php'; $id_array=array('id'=>'1'); echo $client->getName($id_array);