The title says it all. This post is about how PHP5 SoapClient behaves when there is an attachment in the SOAP response.

The scenario:

You request some data from an API, the result set is too large to be sent over SOAP, so the server ┬ásends you a simple valid XML response containing “Return result is too large, Please get your result from attachement”,and the resultset as a CSV document attached ┬áto the response. This makes sense.

The only problem is the default SoapClient in PHP can’t handle this kind of situations. The only thing you get is a SoapException with the following message : looks like we got no XML document.

Why?

Because PHP tries to parse the entire response. and we must face it :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: binary
Content-Id: <the content id>

<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<soapenv:Body>

RESPONSE GOES HERE

</soapenv:Body>

</soapenv:Envelope>

Content-Type: text/plain
Content-Transfer-Encoding: binary
Content-Id: <The second content id>

our pretty huge amount of data in CSV format....

is not a valid XML response at all.

Conclusions:

This is it, if you are facing a problem like this think of this before you panic. Try another Soap library for PHP, there are plenty of them.

OpenSo(u)rcery

Long time, no see. Don't worry, I'm not dead, not even remotely dead. I'm just pretty busy. I'm actually working on great stuff at work and …… Continue reading

Openduty @ Cloud Budapest

Published on April 12, 2015

Leaving Ustream

Published on February 07, 2015