PHP Soap Client That Understands Multi-Part Messages

PHP SOAP client that understands multi-part messages?

The native PHP SoapClient class does not support multipart messages (and is strongly limited in all WS-* matters) and I also I think that neither the PHP written libraries NuSOAP nor Zend_Soap can deal with this sort of SOAP messages.

I can think of two solutions:

  • extend the SoapClient class and overwrite the SoapClient::__doRequest() method to get hold of the actual response string which you can then parse at your whim.

    class MySoapClient extends SoapClient
    {
    public function __doRequest($request, $location, $action, $version, $one_way = 0)
    {
    $response = parent::__doRequest($request, $location, $action, $version, $one_way);
    // parse $response, extract the multipart messages and so on
    }
    }

    This could be somewhat tricky though - but worth a try.

  • use a more sophisticated SOAP client library for PHP. The first and only one that comes into my mind is WSO2 WSF/PHP which features SOAP MTOM, WS-Addressing, WS-Security, WS-SecurityPolicy, WS-Secure Conversation and WS-ReliableMessaging at the cost of having to install a native PHP extension.

Unwanted Strings attached in the start and end of a SOAP response in PHP SoapClient

Those -----Part things are called the boundary in multipart messages explained here and defined in RFC2387.

After an investigation, it seems that SoapClient is incapable of parsing multipart messages, which is why you got that exception.

The solution is to extend SoapClient to extract the XML content with regex or other string functions.
Here is an example from this page:

class MySoapClient extends SoapClient {
public function __doRequest($request, $location, $action, $version, $one_way = 0) {
$response = parent::__doRequest($request, $location, $action, $version, $one_way);
$start = strpos($response,'<?xml');
$end = strrpos($response,'>');
return substr($response,$start,$end-$start+1);
}
}

Zend_Soap with attachments (server)

SOAP attachments are not implemented in the standard PHP SoapServer/SoapClient classes and therefore not available in Zend_Soap which is mainly a wrapper for these.

AFAIK only the PEAR::SOAP class supports attachments but honestly, I gave up and convinced everyone to use base64encoded strings...

I found this blog post describing at least a client solution with PEAR: http://www.casarini.org/blog/2009/php-soap-messages-with-attachments/

SOAP: looks like we got no XML document

A byte order mark (BOM) would have the same effect as whitespace before the php tags.
Here you find a PHP snippet to detect and remove a BOM. Be sure to configure you editor to not insert the BOM again.

Zend Framework - Does Zend_Soap_Client supports SwA (Soap With Attachments)?

Please see my answer here.

ZF's SOAP component is not able to handle multi-part SOAP messages (aka attachments) but I think it's no problem to integrate WSF/PHP into a Zend Framework environment.

File Attachements with PHP5 SOAP

Please see my answer here. Perhaps this may be helpful.



Related Topics



Leave a reply



Submit