Home > Backend Development > PHP Tutorial > Examples of php using soap

Examples of php using soap

WBOY
Release: 2016-07-25 08:56:24
Original
1078 people have browsed it
  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(); 
?> 
Copy after login

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


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template