PHP SOAP client pass array to C# SOAP webservice(PHP SOAP 数组参数传递)
2013-08-15 08:31
435 查看
由于前面同事是用C#实现soap webservice的,有一个函数中用到了数组变量byte [] buffer,这个用C#的soap client是可以毫无压力的实现的,且功能正常。
但是现版本中client需用php来实现,在这个数组变量传递部分卡住了,传递过去的感觉是数组的地址,而非数组内容。
以下是错误代码!!!!
OK,这时候软件对SOAP进行抓包,以下信息眼前一亮。
但是接下来的代码也是错误的!!!!!
百思不得其解中看到了如下信息跟代码:http://php.net/manual/ru/soapclient.soapclient.php,原来SOAP库已经将数据base64了。
If your WSDL file containts a parameter with a base64Binary type, you should not
use base64_encode() when passing along your soap vars. When doing the request, the SOAP library automatically base64 encodes your data, so otherwise you'll be encoding it twice.
所以正确的代码应该是这样的:
花了差不多一天时间才搞定这个问题,简单写了篇博客记录下解决问题的过程,还是得多看php官方的PHP Manual才行。
但是现版本中client需用php来实现,在这个数组变量传递部分卡住了,传递过去的感觉是数组的地址,而非数组内容。
以下是错误代码!!!!
$arybuff =array(1,2,3,4,5,6); $aryPara = array('site'=>5,'cmd'=>2,'buffer'=>$arybuff,'IP'=>'192.168.1.64'); $result1 = $soap->YSSocketSend20($aryPara);php会产生告警,提示将数组转换成了字符串。传递过去的buffer是错误的,并非1,2,3……更像是一个地址值。
OK,这时候软件对SOAP进行抓包,以下信息眼前一亮。
<s:sequence> <s:element minOccurs="1" maxOccurs="1" name="site" type="s:unsignedByte" /> <s:element minOccurs="1" maxOccurs="1" name="cmd" type="s:unsignedShort" /> <s:element minOccurs="0" maxOccurs="1" name="buffer" type="s:base64Binary" /> <s:element minOccurs="0" maxOccurs="1" name="IP" type="s:string" /> </s:sequence>base64Binary,这个是buffer传递的数据类型,知道传递的是什么东西后,接下来的问题就是要将传递的数组转换成base64Binary类型的数据。
但是接下来的代码也是错误的!!!!!
$arybuff =array(1,2,3,4,5,6); $text =""; $i=0; for ( $i=0; $i<count($arybuff);$i++) { $text .= chr($arybuff[$i]); } $text = base64_encode($text); $aryPara = array('site'=>5,'cmd'=>2,'buffer'=>$text,'IP'=>'192.168.1.64'); $result1 = $soap->YSSocketSend20($aryPara);
百思不得其解中看到了如下信息跟代码:http://php.net/manual/ru/soapclient.soapclient.php,原来SOAP库已经将数据base64了。
If your WSDL file containts a parameter with a base64Binary type, you should not
use base64_encode() when passing along your soap vars. When doing the request, the SOAP library automatically base64 encodes your data, so otherwise you'll be encoding it twice.
<?php $string = 'data_you_want_to_send___like_xml_in_soap'; $soap_data = array( 'foo' => 'bar', //'content' => base64_encode($string ) // don't do this 'content' => $string //do this ); $response = $client->Send($soap_data); ?>
所以正确的代码应该是这样的:
$arybuff =array(1,2,3,4,5,6); $text =""; $i=0; for ( $i=0; $i<count($arybuff);$i++) { $text .= chr($arybuff[$i]); } //$text = base64_encode($text); $aryPara = array('site'=>5,'cmd'=>2,'buffer'=>$text,'IP'=>'192.168.1.64'); $result1 = $soap->YSSocketSend20($aryPara);
花了差不多一天时间才搞定这个问题,简单写了篇博客记录下解决问题的过程,还是得多看php官方的PHP Manual才行。
相关文章推荐
- jquery中通过ajax调用webservice传递数组参数的问题
- 关于 php 调用 其他语言写的Web Service SOAP 接口的参数传递问题
- php数组转换为对象PHP - Convert Array to Object with stdClass
- C#形参,实参,值传递参数,引用传递参数,输出参数,参数数组的学习
- C#中数组作为函数参数的传递方式
- c++builder向c#开发的webservice传递非数字参数
- php——SoapClient访问webservice
- C#中客户端创建webservice的soapclient类对象实例时间过长
- java 实现往oracle存储过程中传递array数组类型的参数
- FireFox下为元素附加事件并传递参数-addEventListener attachEvent - Pass parameters to event-function
- PHP通过传递对象参数调用asp.net Webservice 服务
- c++builder向c#开发的webservice传递非数字参数
- jQuery中通过ajax调用webservice传递数组参数的问题实例详解
- C#形参,实参,值传递参数,引用传递参数,输出参数,参数数组的学习
- php——SoapClient访问webservice
- PHP XML To Array,将XML转换为数组
- WebService SOAP WSDL UDDI 使用php的curl、PHP5的SoapClient实现同步
- php 对象数组/传递数组参数
- VBA调用C#对象方法,传递double数组参数
- PHP调用webservice soap soapclient