php 调用webservice的几种方法

前端之家收集整理的这篇文章主要介绍了php 调用webservice的几种方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
PHP调用webservice的几种方法感兴趣的小伙伴,下面一起跟随编程之家 jb51.cc的小编两巴掌来看看吧!

/**
 * PHP调用webservice的几种方法
 *
 * @param 
 * @arrange 512-笔记网: www.512Pic.com
 **/
$soap = new SoapClient("http://192.168.6.69:8899/Service1.asmx?wsdl");
$result2 = $soap->HelloWorld(array(
'myName'=>'aaa','youName'=>'bbb'
));
print_r($result2);
/***   来自编程之家 jb51.cc(jb51.cc)   ***/
2.non-WSDL模式:
2.1使用SoapParam传递参数:

/**
 * PHP调用webservice的几种方法
 *
 * @param 
 * @arrange 512-笔记网: www.512Pic.com
 **/
$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"),"ns1:youName")),array('soapaction'=>'http://tempuri.org/HelloWorld'));
print_r($result2); 
/***   来自编程之家 jb51.cc(jb51.cc)   ***/
2.2使用SoapVar传递参数

/**
 * PHP调用webservice的几种方法
 *
 * @param 
 * @arrange 512-笔记网: www.512Pic.com
 **/
$ns = 'http://tempuri.org/';
$soap = new SoapClient(null,'uri'=>$ns));
$result2 = $soap->__soapCall("HelloWorld",array(new SoapVar("AAA",XSD_STRING,null,$ns,"myName",$ns),new SoapVar("GBBB","youName",$ns)),array('soapaction'=>'http://tempuri.org/HelloWorld'));
print_r($result2);
/***   来自编程之家 jb51.cc(jb51.cc)   ***/
3.添加安全Header

/**
 * PHP调用webservice的几种方法
 *
 * @param 
 * @arrange 512-笔记网: www.512Pic.com
 **/
$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',NULL,$ns_wsse,$ns_wsse);
$passwT = new SoapVar('NnYZe7oD81Kd8QRS4tUMze/2CUs=',$ns_wsse);
$createdT = new SoapVar(time(),XSD_DATETIME,$ns_wsu,$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,'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,$ns_wsse);
$secHeaderValue=new SoapVar($userToken,'Security',$ns_wsse);
$secHeader = new SoapHeader($ns_wsse,$secHeaderValue);
$result2 = $soap->__soapCall("GetDeviceInformation",array(),$secHeader);
echo $result2;
/***   来自编程之家 jb51.cc(jb51.cc)   ***/
原文链接:https://www.f2er.com/php/528106.html

猜你在找的PHP相关文章