德克云技术联盟

会员中心
发新帖
打印 上一主题 下一主题

php调用webservice的几种方法
发布人: 袁康慨 发布时间:2016-03-10 浏览:3737

1.WSDL模式:

[php]

  • $soap = new SoapClient("http://192.168.6.69:8899/Service1.asmx?wsdl");
  • $result2 = $soap->HelloWorld(array(
  •     'myName'=>'aaa',
  •     'youName'=>'bbb'
  • ));
  • print_r($result2);

$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传递参数:

[php]

  • $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);

$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传递参数

[php]

  • $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);

$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
[php]

  • $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;

$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://blog.csdn.net/sagatx/article/details/9318497

分类浏览
关于我们
联系我们
技术联盟
云服务
云技术
云合作
帮助中心
发帖规则
QQ客服
内部通道
企业邮箱
企业论坛
版本选择
手机版
电脑版
用手机扫描下方二维码查看手机版页面

版权所有 西安云联电子科技有限公司
Copyright @ 2011-2022 | decoclouds.com All Rig
陕ICP备13002202号-1

快速回复 返回顶部 返回列表