php调用webservice的几种方法

2018-07-28编程教程
159

1.WSDL模式:

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

 

$ns = 'http://www.genban.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://phpabc.cn/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;



The End

相关推荐

layui根据百度地图经纬度在弹出层中显示位置
首先你需要引入百度地图的js script type="text/javascript" src="https://api.map.baidu.com/api?v=2.0ak=你的ak"/script ak ,注意是要浏览器端的ak,这个直接到百度开发者平台申请。 引入layui,这个大家可以到layui官网看看怎么引入layer, 注意:这里要提...
2025-01-09 编程教程
240

C#之socket编程
编程需要恒心和毅力,最主要的是要有信心,循序渐进的完成任务。 一、socket类用于网络通信 命名空间System.Net.Sockets,完整的类引用System.Net.Sockets.Socket。Socket类支持各种网络协议。 二、简单的控制台程序 using System;using System.Collections....
2023-03-07 编程教程
114

百度UEditor编辑器如何禁止过滤div等网页html标签
将设计排版好的页面html代码上传到数据库,再读取出来的时候发现所有的div都被替换成了p标签。 解决方法: 首先在ueditor.all.js文件内搜索allowDivTransToP,找到如下的代码,将true设置为false me.setOpt({ 'allowDivTransToP':false, 'disabledTableInTable'...
2022-11-23 编程教程
495

Ajax中文传值出现乱码的解决办法
Ajax技术的核心为Javascript,而javascript使用的是UTF-8编码,因此在页面采用GBK或者其他编码,同时没有进行编码转换时,就会出现中文乱码的问题。 以下是分别使用GET和POST方式传值,并且页面采用GBK和UTF-8编码在IE和FF下的不同测试结果和出现乱码时的解...
2022-11-19 编程教程
364

PHP错误Warning: Cannot modify header information - headers alr
今天在用php进行图片保存输出时候,图片一直显示错误,后面用调试模式下提示:Warning: Cannot modify header information - headers already sent by... 看了一些网上的方法也没解决,最后在php.ini配置output_buffering默认为4096就没有遇到这个错误了: o...
2022-05-18 编程教程
69

Parse error: syntax error, unexpected '&'解决办法
在使用PHP5.4及以上版本时,在调用函数时,使用引用符号时,会出现Parse error: syntax error, unexpected 或PHP Fatal error: Call-time pass-by-reference has been removed者,这是由于在函数调用时通过引用传递参数已被弃用,因为它影响了代码的整洁,如...
2022-05-11 编程教程
295