将字节数组从 PHP 发送到 WCF

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

问题描述

我必须从我的 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)