Home >Backend Development >PHP Tutorial >Examples of soap usage in PHP_PHP tutorial

Examples of soap usage in PHP_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:52:30961browse

Usage examples of soap in PHP
There are two ways to use soap in PHP.

1. Use wsdl file

Server side.


{
public function HelloWorld()
{
Return "Hello";
}
public function Add($a,$b)
{
Return $a+$b;
}
}
$server=new SoapServer('soap.wsdl',array('soap_version' => SOAP_1_2));
$server->setClass("service");
$server->handle();
?>

Resource description files can be generated using tools (zend studio). In fact, it is an xml file.





                                                                                                                                                                                                                                                                                                                                                                                                                  
                                                                                                             


                                                                                                                                                                                                        
                                                                                                             


                                                                                                   
              
        

        


                                                                                                       

        
       
      
     
   
 
      
  
 

 
  
 

      
    
    
   

 

 
       transport="http://schemas.xmlsoap.org/soap/http" />
  
   
   
           namespace="http://localhost/interface/" />
   

   
           namespace="http://localhost/interface/" />
   

  

 

 
   
     
   

 

客户端调用

$soap = new SoapClient('http://localhost/interface/soap.wsdl');
echo $soap->Add(1,2);
?>

二、不用wsdl文件

服务器端

 
{
  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();
?>

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478123.htmlTechArticleUsage examples of soap in PHP There are two ways to use soap in PHP. 1. Use wsdl file server side. ?php { public function HelloWorld() { return Hello; } public function Add($a,$b) { re...
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