一、在调试执法办案平台时,连接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();
}
}