博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
php调用webservice的几种方法
阅读量:6078 次
发布时间:2019-06-20

本文共 2902 字,大约阅读时间需要 9 分钟。

原文:php调用webservice的几种方法1.WSDL模式:extension = php_soap.dllextension = php_curl.dllextension = php_openssl.dll  
'值','参数'=>'值');$p = $client->__soapCall('调用方法名',array('parameters' => $param));print_r($p->调用方法名Result);?>$soap = new SoapClient("http://192.168.6.69:8899/Service1.asmx?wsdl");$result2 = $soap->HelloWorld(array( 'myName'=>'aaa', 'youName'=>'bbb'));print_r($result2); 2.non-WSDL模式:2.1使用SoapParam传递参数:$soap = new SoapClient(null,array('location'=>'http://192.168.6.72:8036/Service1.asmx','uri'=>'http://tempuri.org/'));$result2 = $soap->__soapCall("HelloWorld",array(new SoapParam("aaa", "myName"),new SoapParam("bbb", "youName")),//array(new SoapParam("aaa", "ns1:myName"),new SoapParam("bbb", "ns1:youName")),array('soapaction'=>'http://tempuri.org/HelloWorld'));print_r($result2); 2.2使用SoapVar传递参数$ns = 'http://tempuri.org/';$soap = new SoapClient(null,array('location'=>'http://192.168.6.72:8036/Service1.asmx','uri'=>$ns));$result2 = $soap->__soapCall("HelloWorld",array(new SoapVar("AAA", XSD_STRING, null, $ns, "myName", $ns),new SoapVar("GBBB", XSD_STRING, null, $ns, "youName", $ns)),array('soapaction'=>'http://tempuri.org/HelloWorld'));print_r($result2);3.添加安全Header$soap = new SoapClient(null,array('location'=>'http://192.168.6.47/onvif/device_service','uri'=>'http://www.onvif.org/ver10/device/wsdl/'));//ws$ns_wsse = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";//WS-Security namespace$ns_wsu = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd";//WS-Security namespace$userT = new SoapVar('admin', XSD_STRING, NULL, $ns_wsse, NULL, $ns_wsse);$passwT = new SoapVar('NnYZe7oD81Kd8QRS4tUMze/2CUs=', XSD_STRING, NULL, $ns_wsse, NULL, $ns_wsse);$createdT = new SoapVar(time(), XSD_DATETIME, NULL, $ns_wsu, NULL, $ns_wsu);class UsernameT1 {private $Username; //Name must be identical to corresponding XML tag in SOAP headerprivate $Password; // Name must be identical to corresponding XML tag in SOAP header private $Created; function __construct($username, $password, $created) { $this->Username=$username; $this->Password=$password; $this->Created=$created; }}$tmp = new UsernameT1($userT, $passwT, $createdT);$uuT = new SoapVar($tmp, SOAP_ENC_OBJECT, NULL, $ns_wsse, 'UsernameToken', $ns_wsse);class UserNameT2 {private $UsernameToken; //Name must be identical to corresponding XML tag in SOAP headerfunction __construct ($innerVal){ $this->UsernameToken = $innerVal;}}$tmp = new UsernameT2($uuT);$userToken = new SoapVar($tmp, SOAP_ENC_OBJECT, NULL, $ns_wsse, 'UsernameToken', $ns_wsse);$secHeaderValue=new SoapVar($userToken, SOAP_ENC_OBJECT, NULL, $ns_wsse, 'Security', $ns_wsse);$secHeader = new SoapHeader($ns_wsse, 'Security', $secHeaderValue);$result2 = $soap->__soapCall("GetDeviceInformation",array(),null,$secHeader);echo $result2;

 

转载地址:http://bahgx.baihongyu.com/

你可能感兴趣的文章
字符设备与块设备的区别
查看>>
为什么我弃用GNOME转向KDE(2)
查看>>
Redis学习记录初篇
查看>>
爬虫案例若干-爬取CSDN博文,糗事百科段子以及淘宝的图片
查看>>
Web实时通信技术
查看>>
第三章 计算机及服务器硬件组成结合企业运维场景 总结
查看>>
IntelliJ IDEA解决Tomcal启动报错
查看>>
默认虚拟主机设置
查看>>
php中的短标签 太坑人了
查看>>
[译] 可维护的 ETL:使管道更容易支持和扩展的技巧
查看>>
### 继承 ###
查看>>
数组扩展方法之求和
查看>>
astah-professional-7_2_0安装
查看>>
函数是对象-有属性有方法
查看>>
uva 10107 - What is the Median?
查看>>
Linux下基本栈溢出攻击【转】
查看>>
c# 连等算式都在做什么
查看>>
使用c:forEach 控制5个换行
查看>>
java web轻量级开发面试教程摘录,java web面试技巧汇总,如何准备Spring MVC方面的面试...
查看>>
使用ansible工具部署ceph
查看>>