<small id='99xlE'></small><noframes id='99xlE'>

<tfoot id='99xlE'></tfoot>

        • <bdo id='99xlE'></bdo><ul id='99xlE'></ul>

        <i id='99xlE'><tr id='99xlE'><dt id='99xlE'><q id='99xlE'><span id='99xlE'><b id='99xlE'><form id='99xlE'><ins id='99xlE'></ins><ul id='99xlE'></ul><sub id='99xlE'></sub></form><legend id='99xlE'></legend><bdo id='99xlE'><pre id='99xlE'><center id='99xlE'></center></pre></bdo></b><th id='99xlE'></th></span></q></dt></tr></i><div id='99xlE'><tfoot id='99xlE'></tfoot><dl id='99xlE'><fieldset id='99xlE'></fieldset></dl></div>
        <legend id='99xlE'><style id='99xlE'><dir id='99xlE'><q id='99xlE'></q></dir></style></legend>

      1. 将字节数组从 PHP 发送到 WCF

        时间:2023-05-22

        <tfoot id='tR9kP'></tfoot>

        <legend id='tR9kP'><style id='tR9kP'><dir id='tR9kP'><q id='tR9kP'></q></dir></style></legend>
        • <bdo id='tR9kP'></bdo><ul id='tR9kP'></ul>
            <tbody id='tR9kP'></tbody>
            <i id='tR9kP'><tr id='tR9kP'><dt id='tR9kP'><q id='tR9kP'><span id='tR9kP'><b id='tR9kP'><form id='tR9kP'><ins id='tR9kP'></ins><ul id='tR9kP'></ul><sub id='tR9kP'></sub></form><legend id='tR9kP'></legend><bdo id='tR9kP'><pre id='tR9kP'><center id='tR9kP'></center></pre></bdo></b><th id='tR9kP'></th></span></q></dt></tr></i><div id='tR9kP'><tfoot id='tR9kP'></tfoot><dl id='tR9kP'><fieldset id='tR9kP'></fieldset></dl></div>

            <small id='tR9kP'></small><noframes id='tR9kP'>

                  本文介绍了将字节数组从 PHP 发送到 WCF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我必须从我的 PHP 客户端向 WCF 主机发送一个字节数组(编码照片).当我在 PHP 中对我的数组执行 var_dump() 时,我得到一个数组 [2839],这是可以的,但是在服务器端,当我调试时,我看到收到的数组只是字节 [5] ......知道如何修复它吗?

                  I have to send a byte array (encoded photo) from my PHP client to the WCF host. when I do a var_dump() on my array in PHP I get an array[2839] which is ok but on the server side when I debug I see that received array is only byte[5]... Any idea how I can fix it?

                  我用过这样的代码

                  $file = file_get_contents($_FILES['Filedata']['tmp_name']);
                          $byteArr = str_split($file);
                          foreach ($byteArr as $key=>$val) { $byteArr[$key] = ord($val); }
                  
                  $client = new SoapClient('http://localhost:8000/MgrService?wsdl',
                                      array(
                                      'location' => 'http://localhost:8000/MgrService/SOAP11',
                                      'trace' => true,
                                      'soap_version' => SOAP_1_1
                                      ));
                    $par1->profileId = 13;
                    $par1->photo = $byteArr;          
                  
                    $client->TestByte($par1);
                  

                  正如我之前在 wcf 主机上写的那样,我只得到字节 [5] :/也许它需要一些解码才能正确地序列化肥皂?我应该使用 Base64 解码还是什么?

                  And as I wrote earlier on the wcf host I get only byte[5] :/ maybe it needs some decoding to right soap serialize? should I use Base64 decoding or something?

                  一般我只想以字节[]为参数将发布的文件上传到c#函数:/帮助

                  General I just want to upload posted file to c# function with byte[] as parameter :/ Help

                  哦,这个函数的 wsdl 部分看起来像这样

                  Oh and the wsdl part of this function looks like this

                  <xs:element name="TestByte">
                  <xs:complexType>
                  <xs:sequence>
                  <xs:element minOccurs="0" name="photo" nillable="true" type="xs:base64Binary"/>
                  </xs:sequence>
                  </xs:complexType>
                  </xs:element>
                  

                  推荐答案

                  您应该在 PHP 中使用字符串来模拟字节数组.您甚至可以将语法 $str[index] 与字符串一起使用.否则,您将有巨大的开销(4 倍或 8 倍,具体取决于有效负载的整数大小加上哈希表开销).

                  You should use strings in PHP to emulate byte arrays. You can even use the syntax $str[index] with strings. You have a HUGE overhead (4x or 8x depending on the int size the payload PLUS the hash table overhead) otherwise.

                  我不太熟悉 SOAP 扩展所做的类型转换,但使用字符串可能会起作用.

                  I'm not very familiar with the type conversions the SOAP extension does, but using a string instead will probably work.

                  刚刚检查了来源:

                  if (Z_TYPE_P(data) == IS_STRING) {
                      str = php_base64_encode((unsigned char*)Z_STRVAL_P(data), Z_STRLEN_P(data), &str_len);
                      text = xmlNewTextLen(str, str_len);
                      xmlAddChild(ret, text);
                      efree(str);
                  }
                  

                  所以它已经为你做了 base 64 编码.

                  So it already does the base 64 encoding for you.

                  [推测]

                  您的 5 字节长结果是因为按照上面的代码转换为字符串:

                  Your 5-byte long result is because of the conversion to string that follows the code above:

                  if (Z_TYPE_P(data) == IS_STRING) {
                          ...
                  } else {
                      zval tmp = *data;
                  
                      zval_copy_ctor(&tmp);
                      convert_to_string(&tmp);
                      str = php_base64_encode((unsigned char*)Z_STRVAL(tmp), Z_STRLEN(tmp), &str_len);
                      text = xmlNewTextLen(str, str_len);
                      xmlAddChild(ret, text);
                      efree(str);
                      zval_dtor(&tmp);
                  }
                  

                  转换结果为数组",长度为 5 个字节.

                  The conversion results in "Array", which is 5 bytes long.

                  这篇关于将字节数组从 PHP 发送到 WCF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:PHP 中的 SoapClient 错误回退 下一篇:PHP中P_SHA1算法的实现

                  相关文章

                  最新文章

                    <bdo id='lzks4'></bdo><ul id='lzks4'></ul>

                    1. <small id='lzks4'></small><noframes id='lzks4'>

                    2. <tfoot id='lzks4'></tfoot>
                      <i id='lzks4'><tr id='lzks4'><dt id='lzks4'><q id='lzks4'><span id='lzks4'><b id='lzks4'><form id='lzks4'><ins id='lzks4'></ins><ul id='lzks4'></ul><sub id='lzks4'></sub></form><legend id='lzks4'></legend><bdo id='lzks4'><pre id='lzks4'><center id='lzks4'></center></pre></bdo></b><th id='lzks4'></th></span></q></dt></tr></i><div id='lzks4'><tfoot id='lzks4'></tfoot><dl id='lzks4'><fieldset id='lzks4'></fieldset></dl></div>
                      <legend id='lzks4'><style id='lzks4'><dir id='lzks4'><q id='lzks4'></q></dir></style></legend>