php调用webservice的几种方法

简介: 原文:php调用webservice的几种方法 1.WSDL模式: extension = php_soap.dll extension = php_curl.dll extension = php_openssl.
原文:php调用webservice的几种方法

1.WSDL模式:

extension = php_soap.dll

extension = php_curl.dll

extension = php_openssl.dll

 

 

<?php

header("content-type:text/html;charset=utf-8");

$client = new SoapClient("http://url/ooxx.asmx?wsdl");

$param = array('参数'=>'值','参数'=>'值');

$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 header
private $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 header
function __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;

 

目录
相关文章
|
14天前
|
缓存 PHP 开发者
PHP中的自动加载机制及其优化方法
传统的PHP开发中,经常会遇到类文件加载繁琐、效率低下的情况,而PHP的自动加载机制能够很好地解决这一问题。本文将深入探讨PHP中的自动加载机制,介绍其原理及实现方式,并提出了一些优化方法,帮助开发者提升代码加载效率,提高应用性能。
|
26天前
|
SQL 缓存 PHP
PHP技术探究:优化数据库查询效率的实用方法
本文将深入探讨PHP中优化数据库查询效率的实用方法,包括索引优化、SQL语句优化以及缓存机制的应用。通过合理的优化策略和技巧,可以显著提升系统性能,提高用户体验,是PHP开发者不容忽视的重要议题。
|
4月前
|
JSON PHP 数据格式
PHP curl方法封装
PHP curl方法封装
30 0
|
4月前
|
安全 小程序 PHP
PHP代码审计(五)PHP代码审计方法与步骤
(1):获取到网站源码(这就是废话……) (2):将网站部署到你自己的环境中,能运行。 这里特殊说明一下我的习惯,我本地的环境与线上的环境基本上保持一致,这样在本地审计及线上部署的时候能发现更多的问题。不建议说是随便搭个环境能跑起来就行,这样不是很严谨。 (3):拿到源码之后,浏览大概的项目结构。
64 0
|
4月前
|
PHP
PHP显示报错提示,开启display_errors的方法
PHP显示报错提示,开启display_errors的方法
46 0
|
6月前
|
数据采集 定位技术 PHP
简单而高效:使用PHP爬虫从网易音乐获取音频的方法
网易音乐是一个流行的在线音乐平台,提供了海量的音乐资源和服务。如果你想从网易音乐下载音频文件,你可能会遇到一些困难,因为网易音乐对其音频资源进行了加密和防盗链的处理。本文将介绍一种使用PHP爬虫从网易音乐获取音频的方法,该方法简单而高效,只需几行代码就可以实现。
简单而高效:使用PHP爬虫从网易音乐获取音频的方法
|
4月前
|
PHP 调度
PHP 定时任务方法封装
PHP 定时任务方法封装
30 0
|
4月前
|
PHP
PHP 魔幻(术)方法 & 魔术常量
PHP 魔幻(术)方法 & 魔术常量
24 0