专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > XML/SOAP

初识php soap 学习历程中的摘抄,便于后期翻阅

发布时间:2010-05-20 14:01:29 文章来源:www.iduyao.cn 采编人员:星星草
初识php soap 学习过程中的摘抄,便于后期翻阅

SOAP 简单对象访问协议,

webService三要素 , SOAP、WSDL(WebServicesDescriptionLanguage)、UDDI(UniversalDescriptionDiscovery andIntegration)之一, soap用来描述传递信息的格式, WSDL 用来描述如何访问具体的接口, uddi用来管理,分发,查询webService 。

一,首先要设置服务器环境。
修改php.ini 
得添加extension=php_soap.dll (加载soap 内置包) 
修改soap.wsdl_cache_enabled=1 改为soap.wsdl_cache_enabled=0 这个是soap的缓存,测试的时候最好改为0,上线稳定了改为1
 
soap有两种模式一种是wsdl,一种是no-wsdl
 
二,熟悉几个函数

一、SoapServer 服务器

1、__construct
作用:创建 SoapServer 对象
用法:__construct ( mixed wsdl [, array options] )
参数:wsdl 文件地址,options soap_version,encoding,actor,classmap
返回:对象

2、addFunction
作用:为客户端导出一个或多个函数
用法:addFunction ( mixed functions )
参数:functions 函数,一个或多个,全部 SOAP_FUNCTIONS_ALL
返回:无

3、getFunctions
作用:获取全部函数
用法:getFunctions ()
参数:无
返回:函数数组

4、setClass
作用:导出类中的全部函数
用法:setClass ( string class_name [, mixed args [, mixed ...]] )
参数:class_name 类名 args 参数
返回:无

5、setPersistence
作用:允许保存在PHP之间的会话请求数据
用法:setPersistence ( int mode )
参数:mode SOAP_PERSISTENCE_SESSION SOAP_PERSISTENCE_REQUEST
返回:无

6、fault
作用:允许保存在PHP之间的会话请求数据
用法:fault ( string code, string string [, string actor [, mixed details [, string name]]] )
参数:code 错误代码 string 简短错误信息 actor 导致错误的字符串 details 错误详细信息
返回:无

7、handle ( [string soap_request] )
作用:处理一个SOAP请求,调用必要的功能,并发送回一个响应。
用法:handle ( [string soap_request] )
参数:soap_request 请求
返回:无

二、SoapClient 客户端

1、__construct
作用:创建 SoapClient 对象
用法:__construct ( mixed wsdl [, array options] )
参数:wsdl 文件地址 或 null,
options
a、soap_version soap版本,encoding 编码,compression 压缩,classmap
b、http身份验证 :login , password
c、代理服务:proxy_host, proxy_port, proxy_login and proxy_password
d、证书验证:local_cert , passphrase
e、wsdl 为null 时:location , uri
返回:对象

2、__call
作用:调用函数
用法:__call ( string function_name, array arguments [, array options [, array input_headers [, array output_headers]]] )
参数:function_name,arguments
返回:无

3、__doRequest
作用:在执行HTTP请求
用法:__doRequest ( string request, string location, string action, int version [, int one_way] )
参数:request XML的SOAP请求 location 请求地址 action ,version
返回:字符串

4、__getFunctions
作用:获取全部方法
用法:__getFunctions( )
参数:无
返回:函数数组

5、__getFunctions
作用:获取全部方法
用法:__getFunctions( )
参数:无
返回:函数数组

6、__setCookie
作用:设置cookie
用法:__setCookie ( string name [, string value] )
参数:name cookie名称 value cookie值
返回:无

7、__getLastRequest
作用:获取最后的请求
用法:__getLastRequest ()
参数:无
返回:最后的请求

8、__getLastRequestHeaders
作用:获取最后的请求头部信息
用法:__getLastRequestHeaders ()
参数:无
返回:最后的请求头部信息

9、__getLastResponse
作用:获取最后的回应
用法:__getLastRequest ()
参数:无
返回:最后的请求回应

10、__getLastResponseHeaders
作用:获取最后的回应头部信息
用法:__getLastResponseHeaders ()
参数:无
返回:最后的回应头部信息

三、SoapVar 参数

1、__construct
作用:创建 SoapVar 对象
用法:__construct ( mixed data, int encoding [, string type_name [, string type_namespace [, string node_name [, string node_namespace]]]] )
参数:data 数据,encoding 编码
返回:参数对象

四、SoapParam 参数

1、__construct
作用:创建 SoapParam 对象
用法:__construct ( mixed data, string name )
参数:data 传递的变量,name 变量的值
返回:参数对象

__construct ( string namespace, string name [, mixed data [, bool mustUnderstand [, mixed actor]]] )

五、SoapHeader 头部

1、__construct
作用:创建 SoapHeade 对象
用法:__construct ( string namespace, string name [, mixed data [, bool mustUnderstand [, mixed actor]]] )
参数: namespace 命名空间 name SOAP 头标签名称 ,data 头部内容
返回:对象

六、SoapFault 头部

1、__construct
作用:创建 SoapFault 对象
用法:__construct ( string faultcode, string faultstring [, string faultactor [, mixed detail [, string faultname [, SoapHeader headerfault]]]] )
参数: faultcode 错误代码,faultstring 错误信息 ,faultactor 导致错误字符串,detail 错误详情
返回:对象

七、例子

1、定义一个类

class Calculator
{
    public function sum($x,$y)
     {
         return $x + $y;
     }
}
2、使用Zend Studio生成wsdl文件;

3、SOAP 服务器端 (server.php)

require './Calculator.php';

$server = newSoapServer('./wps.wsdl');
$server->setClass('Culculator');
$server->handle();
3、SOAP 客户端(client.php)

查看源码 复制到剪切板 打印 帮助
$soap  = newSoapClient( './wps.wsdl' );  
echo   $soap ->sum(1,2);  
//运行输出 3  

 

友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: