Usage examples of soap in PHP, PHPsoap usage examples
The examples in this article describe the usage of soap in PHP and are shared with everyone for your reference. The specific usage analysis is as follows:
PHP There are two ways to use soap.
1. Use wsdl file
Server side:
Copy code The code is as follows:
class service
{
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.
Copy code The code is as follows:
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文件
服务器端:
复制代码 代码如下:
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();
?>
客户端:
复制代码 代码如下:
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);
}
?>
希望本文所述对大家的PHP程序设计有所帮助。
How to determine that it cannot be used? Without pictures and facts, it is impossible to determine the cause of the error (only php5 and above support soap)
try {
$this->soap-> = new SoapClient ( "localhost/WebService.asmx?wsdl" );//Note that this is the asmx service using c#.
$ obj = $this->soap->webservice method name (array ("server parameter name"=>"parameter value","second server parameter name"=>"second parameter value") ) ;
return $this->json_decode_CSharp ($obj);//Here are different parsing bodies implemented according to different SERVICE (we return JSON data).json_decode_csharp is my custom function
} catch ( Exception $e ) {
$this->file->vim ( $e->__toString (), $this->logpath . date ( "Ymd" ) . ".log" );
return null;
}
You can join the PHP learning exchange group and ask in the group: 40383880
http://www.bkjia.com/PHPjc/899063.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/899063.htmlTechArticleUsage examples of soap in PHP, PHPsoap usage examples This article describes the usage of soap in PHP, share it with everyone For everyone’s reference. The specific usage analysis is as follows: There are two ways to use soap in PHP. ...