How to handle PHP soapclient multipart response with binary attachment

I got a soapclient response which is multipart with binary attachment. Now I use native method to get the XML into Array. But I don’t know how to handle the binary part. Anybody has idea how to solve it?

PHP script to do the XML part :

$soapOption = array(
    'location' => 'https://www.elevy-ticf-train.org.hk:8443/ELevyService.svc',
    'trace' => true,
    'exceptions' => false,
    'soap_version' => 'SOAP_1_2',
    'encoding' => 'utf-8'
);

$client = new SoapClient('test.wsdl', $soapOption);

$client->LevyEFrank($data);
$response = $client->__getLastResponse();
$dom = new DomDocument();
@$dom->loadHtml($response);

$xmlScrope = $dom->getElementsByTagName('levyefrankresult');
$xmlRespone = $xmlScrope->item(0)->getElementsByTagName('*');

$stamp = array();

foreach ($xmlRespone as $element) {
    $stamp[$element->tagName] = $element->nodeValue;
}
var_dump($stamp);

Sample of soapclient response :

Do you want to save the png to disk, output in browser, or something else?

__getLastResponse is only there for debugging, it should not be used to really obtain the answer.

What happens when you do this:

$soapOption = array(
    'location' => 'https://www.elevy-ticf-train.org.hk:8443/ELevyService.svc',
    'trace' => true,
    'exceptions' => false,
    'soap_version' => 'SOAP_1_2',
    'encoding' => 'utf-8'
);

$client = new SoapClient('test.wsdl', $soapOption);

$result = $client->LevyEFrank($data);

var_dump($result);

?

Save to disk.

On server soap side, it will return multipart (xml + binary). So the $result will be returned soapfault that it is not xml. As a result, never get the normal return from $client->LevyEFrank($data). The way I can get something return is $client->__getLastResponse().

Nice, so they implement a standard but they’re not adhering to it… :woman_facepalming:

I DO think so. The server MAY be written on ASP .NET infrastructure. And the return value is embedded with a binary picture (.png) not base64 string. As a result, the return value is pretty complex (multipart). Unfortunately, I cannot control of server side because of it is managed by government organisation.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.