PHP连接webservice调试相关
来源:互联网 发布:订货软件破解版 编辑:程序博客网 时间:2024/06/11 16:51
一、在调试执法办案平台时,连接webservice时,程序参考易工的做法:
function post_playurlinfo_webservice($p_array){$result_array = array();error_log(date("Y-m-d H:i:s")." webservice begin:".$p_array."\n", 3, 'sanheyi_test.log');try{$client = new SoapClient("http://ip/zfpt/services/YSPInfoService?wsdl",array('encoding'=>'UTF-8')); //测试ip}catch (Exception $e){error_log(date("Y-m-d H:i:s")." webservice soapclient error:".$e->getMessage()."\n", 3, 'sanheyi_test.log');$result_array['state'] = "false";$result_array['msg'] = '连接到执法办案平台失败';return $result_array;}error_log(date("Y-m-d H:i:s")." webservice begin:shilihua chenggong \n", 3, 'sanheyi_test.log');try{$param = array('jsonData'=>$p_array);$arrResult = $client->submitAlarmMaterial($param);//$arrResult = $client->__Call('submitAlarmMaterial',$param);error_log(date("Y-m-d H:i:s")." webservice result:".$arrResult->out."\n", 3, 'sanheyi_test.log');}catch (Exception $e){error_log(date("Y-m-d H:i:s")." webservice call error:".$e->getMessage()."\n", 3, 'sanheyi_test.log');$result_array['state'] = "false";$result_array['msg'] = '连接成功,但运行上报函数报错';return $result_array;}$array_temp = json_decode($arrResult->out,true);$result_array['state'] = $array_temp['success'];$result_array['msg'] = $array_temp['message'];return $result_array;}
以上差不多最终的程序,但还是有问题,我们还在调试中,但调通了。
二、注意的一点就是:
Java Xfire发布的WebService服务,PHP调用test()方法成功!
若调用有参数如test2(int x)则PHP报 Not enough message parts were received for the operation. 的错误信息.请问这个问题怎么处理(详细点)?
若调用有参数如test2(int x)则PHP报 Not enough message parts were received for the operation. 的错误信息.请问这个问题怎么处理(详细点)?
Java服务端使用XFire后来发现必须要用数组的方式传递参数$param1 =" hello";$param = array('inPara'=>$param1); $arr = $client->HelloService($param);如果直接用 $arr = $client->HelloService($param1);,上面的异常就会出现参数名inPara也要和wsdl中定义的一致,否则会出其他问题。自己总算在网上找到答案了。。呵呵。。
3、以上走了一些弯路,另外他们返回的参数,说是字符串,其它返回的是个对象,调试的时候可以另外写个页面去调试,否则我们的日志打印不出来结果,一直是空。如:
<?php$soap=new SoapClient('http://ip/zfpt/services/YSPInfoService?wsdl');//$soap=new SoapClient('http://www.daimajiayuan.com/javascript-function/677.html/service/searchFlightService2.0?wsdl',array('encoding'=>'UTF-8'));带参数的调用方式/*echo '<pre>';print_r($soap->__getFunctions());//列出当前SOAP所有的方法,参数和数据类型,也可以说是获得web service的接口print_r($soap->__getTypes());//列出每个web serice接口对应的结构体echo '</pre>';*/$arr_shanchu_json = '[{ "JJBH": "37018120150101092730000130", "CZRSFZH": "330481198805160127", "SCSJ": "20150131203008", "SLRSFZH": "330481198608130258", "SLSJ": "20150129212833", "CLLX": "01", "SLT": "5rWL6K+V5a2X56ym5Liy", "BFDZ": "http://127.0.0.1:8080/Demo/play.jsp?id=012328", "CLBH": "012328", "CLMC": "李兴勤审问的视频", "CLMS": "对嫌疑人李兴勤审问的视频信息", "BFSC":"180", "CLFL":"02", "RYBH":"R3707815000002014010015", "RYLX":"0103"},{ "JJBH": "37018120150101092730000130", "CZRSFZH": "330481198805160127", "SCSJ": "20150131203008", "SLRSFZH": "330481198608130258", "SLSJ": "20150129212833", "CLLX": "01", "SLT": "5rWL6K+V5a2X56ym5Liy", "BFDZ": "http://127.0.0.1:8080/Demo/play.jsp?id=012328", "CLBH": "012135", "CLMC": "李兴勤审问的视频", "CLMS": "对嫌疑人李兴勤审问的视频信息", "BFSC":"180", "CLFL":"02", "RYBH":"R3707815000002014010015", "RYLX":"0501"}]';$param = array('jsonData'=>$arr_shanchu_json);$arrResult = $soap->submitAlarmMaterial($param);echo '<pre>';print_r('test....');var_dump($arrResult);print_r('**************');var_dump($arrResult->out);//列出当前SOAP所有的方法,参数和数据类型,也可以说是获得web service的接口/*$array_temp = json_decode($arrResult['out'],true);if($array_temp['success'] == "false"){echo '***********fail*******';}else{echo '***********success*******';}*/echo '</pre>';?>
四、后来发现还是不行,java服务器那边反馈,一直接收不到我们参数,但其实,我们已经连接成功了,是我忽视了前面的一句话:【参数名inPara也要和wsdl中定义的一致】,使用下述的代码,可以得到Java服务器那一端的所有函数与参数名:
<?php$soap=new SoapClient('http://ip/zfpt/services/YSPInfoService?wsdl');//$soap=new SoapClient('http://www.daimajiayuan.com/javascript-function/677.html/service/searchFlightService2.0?wsdl',array('encoding'=>'UTF-8'));带参数的调用方式echo '<pre>';print_r($soap->__getFunctions());//列出当前SOAP所有的方法,参数和数据类型,也可以说是获得web service的接口print_r($soap->__getTypes());//列出每个web serice接口对应的结构体echo '</pre>';运行上述代码,得到:
Array( [0] => removeAlarmMaterialResponse removeAlarmMaterial(removeAlarmMaterial $parameters) [1] => submitAlarmMaterialResponse submitAlarmMaterial(submitAlarmMaterial $parameters) [2] => removeCaseMaterialResponse removeCaseMaterial(removeCaseMaterial $parameters) [3] => submitCaseMaterialResponse submitCaseMaterial(submitCaseMaterial $parameters))Array( [0] => struct removeAlarmMaterial { string in0;} [1] => struct removeAlarmMaterialResponse { string out;} [2] => struct submitAlarmMaterial { string in0;} [3] => struct submitAlarmMaterialResponse { string out;} [4] => struct removeCaseMaterial { string in0;} [5] => struct removeCaseMaterialResponse { string out;} [6] => struct submitCaseMaterial { string in0;} [7] => struct submitCaseMaterialResponse { string out;})通过上述代码,知道了参数名应该是【in0】,我真是无语了。改了这个之后,就彻底好了,java那边也能收到数据了。也是在网络上面看到的答案,最终的代码如下:
function post_playurlinfo_webservice($p_array){$result_array = array();error_log(date("Y-m-d H:i:s")." webservice begin:".$p_array."\n", 3, 'sanheyi_test.log');//$parray = new ArrayObject($p_array);try{$client = new SoapClient("http://ip/zfpt/services/YSPInfoService?wsdl",array('encoding'=>'UTF-8')); //正式ip}catch (Exception $e){error_log(date("Y-m-d H:i:s")." webservice soapclient error:".$e->getMessage()."\n", 3, 'sanheyi_test.log');$result_array['state'] = "false";$result_array['msg'] = '连接到执法办案平台失败';return $result_array;}error_log(date("Y-m-d H:i:s")." webservice begin:shilihua chenggong \n", 3, 'sanheyi_test.log');try{$param = array('in0'=>$p_array);$arrResult = $client->submitAlarmMaterial($param);//$arrResult = $client->__Call('submitAlarmMaterial',$param);error_log(date("Y-m-d H:i:s")." webservice result:".$arrResult->out."\n", 3, 'sanheyi_test.log');}catch (Exception $e){error_log(date("Y-m-d H:i:s")." webservice call error:".$e->getMessage()."\n", 3, 'sanheyi_test.log');$result_array['state'] = "false";$result_array['msg'] = '连接成功,但运行上报函数报错';return $result_array;}$array_temp = json_decode($arrResult->out,true);$result_array['state'] = $array_temp['success'];$result_array['msg'] = $array_temp['message'];return $result_array;}controller那边调用的程序如下,具体参考此项目吧:
$arr_shanchu_json = "[{";$arr_shanchu_json .= '"JJBH":"'.$casetopic.'",';$arr_shanchu_json .= '"CZRSFZH":"'.$user_idcard.'",';$arr_shanchu_json .= '"SCSJ":"'.date('YmdHis',time()).'",';$arr_shanchu_json .= '"SLRSFZH":"",';$arr_shanchu_json .= '"SLSJ":"",';$arr_shanchu_json .= '"CLLX":"'.$cllx.'",';$arr_shanchu_json .= '"SLT":"",';$arr_shanchu_json .= '"BFDZ":"'.$bfdz.'",';$arr_shanchu_json .= '"CLBH":"'.$media['id'].'",';$arr_shanchu_json .= '"CLMC":"'.$media['bfilename'].'",';$arr_shanchu_json .= '"CLMS":"'.$media['note'].'",';$arr_shanchu_json .= '"BFSC":"'.$playtime."".'",';$arr_shanchu_json .= '"CLFL":"01",';$arr_shanchu_json .= '"RYBH":"",';$arr_shanchu_json .= '"RYLX":""';$arr_shanchu_json .= "}]";$res = $media_m->post_playurlinfo_webservice($arr_shanchu_json);if(empty($res)){$result_array['state'] = 'fail';$result_array['msg'] = '数据上传失败,请稍后重试!';echo json_encode($result_array);exit();}else{if($res['state'] == "true"){$media_m->updateRow("id={$media['id']}", array('casetopic'=>$casetopic));$result_array['state'] = 'success';$result_array['msg'] = '成功上传数据!';$log_m = new LogModel();$log_m->writeLog("032","文件记录名:".$media['filename'].'成功关联到案件号:'.$casetopic);echo json_encode($result_array);exit();}else{$result_array['state'] = 'fail';$result_array['msg'] = $res['msg'];echo json_encode($result_array);exit();}}
0 0
- PHP连接webservice调试相关
- php调试相关技术
- php 调试相关
- WebService /php soap 相关调用 收藏
- php连接webservice传入自定义对象
- wpa_cli P2P 连接相关调试命令
- wpa_cli P2P 连接相关调试命令
- wpa_cli P2P 连接相关调试命令
- 调试webservice
- webservice调试
- webService调试
- 调试webservice
- WebService相关
- webservice相关
- Webservice 相关
- phpstorm8连接xdebug来调试php
- phpstorm8连接xdebug来调试php
- phpstorm8连接xdebug来调试php
- RN布局(二)——伸缩容器的属性
- oracle execute immediate 权限不足ora-01031
- 编写高质量的JavaScript代码
- 基于Mybatis分页插件PageHelper实现分页功能
- 冒泡排序(面向对象)
- PHP连接webservice调试相关
- [Leetcode] Lowest Common Ancestor of a Binary Tree 最小公共祖先
- CreateThread和_beginthread区别及使用
- RN布局(三)——伸缩项目的属性
- mysql在java中处理update语句使用了表别名,不起作用
- 二叉树的基本操作--递归
- 内存恶鬼drawRect
- SwipeRefreshLayout、ScrollView、RecyclerView嵌套使用
- 面试常用排序算法