search
Homephp教程php手册PHP中soap的使用例子

PHP中soap的使用例子

Jun 13, 2016 am 10:50 AM
phpsoaponeuseexampleWayhaveuseof

PHP中soap的使用例子
PHP 使用soap有两种方式。

一、用wsdl文件

服务器端。

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

资源描述文件,可以用工具(zend studio)生成。其实就是一个xml文件。


 
   
     
       
         
           
         

       

     

     
       
         
           
         

       

     

     
      
       
        
       

      

     

     
      
       

        
       
      
     
   
 
      
  
 

 
  
 

      
    
    
   

 

 
       transport="http://schemas.xmlsoap.org/soap/http" />
  
   
   
   
           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);
}
?>

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version