tags:

views:

90

answers:

1

Hi I have this problem:

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?

I used code like this

$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);

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

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

Oh and the wsdl part of this fuction 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>
A: 

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.

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

EDIT: Just checked the sources:

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);
}

So it already does the base 64 encoding for you.

EDIT2: [SPECULATION]

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);
}

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

Artefacto
could you please provide some sample code for that?right now my starting point is thah I have $_FILES['Filedata'] and I've tried many different aproaches :/
shin
@shin Pass `$_FILES['Filedata']` unchanged.
Artefacto
@shin I meant pass `file_get_contents($_FILES['Filedata']['tmp_name'])` unchanged.
Artefacto
Ok I see that some things for me are quite black magic, especially does sources ;) nevertheless You were absolutly right :) the answer was just to do $file = file_get_contents($_FILES['Filedata']['tmp_name']);and then $par1->photo = $file;
shin