PHP中soap的用法实例,PHPsoap用法实例
本文实例讲述了PHP中soap的用法,分享给大家供大家参考。具体用法分析如下:
PHP 使用soap有两种方式。
一、用wsdl文件
服务器端:
复制代码 代码如下:
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();
?>
资源描述文件,可以用工具(zend studio)生成。其实就是一个xml文件。
复制代码 代码如下:
客户端调用:
复制代码 代码如下:
$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程序设计有所帮助。
怎么断定他无法使用,无图无真相无法判断错误原因(php5以上才支持soap的呢)
try {
$this->soap-> = new SoapClient ( "localhost/WebService.asmx?wsdl" );//注意这里是用c#的asmx服务.
$obj = $this->soap->webservice方法名 ( array ("服务器参数名"=>"参数值","第二个服务器参数名"=>"第二个参数值") );
return $this->json_decode_CSharp ( $obj );//这里是根据不同的SERVICE实现了不同的解析体(我们回传的是JSON数据).json_decode_csharp是我自定义函数
} catch ( Exception $e ) {
$this->file->vim ( $e->__toString (), $this->logpath . date ( "Ymd" ) . ".log" );
return null;
}
可以加php学习交流群到群里问:40383880
http://www.bkjia.com/PHPjc/899063.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/899063.htmlTechArticlePHP中soap的用法实例,PHPsoap用法实例 本文实例讲述了PHP中soap的用法,分享给大家供大家参考。具体用法分析如下: PHP 使用soap有两种方式。...
Stellungnahme:Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn