Home  >  Article  >  Backend Development  >  Examples of php using soap

Examples of php using soap

WBOY
WBOYOriginal
2016-07-25 08:56:241059browse
  1. $soap = new SoapServer($wsdl,$array);
Copy code

2, SoapClient

  1. $soap = new SoapClient($wsdl,$array);
Copy code

3, SoapFault

  1. $fault = new SoapFault($faultcode,$faultstring);
Copy code

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); 
} 
?> 


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn