Home > Article > Backend Development > Examples of php using soap
2, SoapClient
3, SoapFault
Two reference methods: Method 1, introduce wsdl file. Method 2, do not use wsdl file. The following example is the method without using wsdl file. Server side code: <?php class service { public function HelloWorld() { return "Hello"; } public function Add($a,$b) { return $a+$b; } } $server=new SoapServer(null,array('uri' => "abcd")); $server->setClass("service"); $server->handle(); ?> Client code: <?php try{ $soap = new SoapClient(null,array( "location" => "http://localhost/interface/soap.php", "uri" => "abcd", //资源描述符服务器和客户端必须对应 "style" => SOAP_RPC, "use" => SOAP_ENCODED )); echo $soap->Add(1,2); }catch(Exction $e){ echo print_r($e->getMessage(),true); } ?> |