Skip to content

Instantly share code, notes, and snippets.

@pkmishra
Created March 29, 2012 19:57
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pkmishra/2243055 to your computer and use it in GitHub Desktop.
Save pkmishra/2243055 to your computer and use it in GitHub Desktop.
PHP SOAP client to handle mtom message encoding
/**
* This client extends the ususal SoapClient to handle mtom encoding. Due
* to mtom encoding soap body has test apart from valid xml. This extension
* remove the text and just keeps the response xml.
*/
class MTOMSoapClient extends SoapClient {
public function __doRequest($request, $location, $action, $version, $one_way = 0) {
$response = parent::__doRequest($request, $location, $action, $version, $one_way);
//if resposnse content type is mtom strip away everything but the xml.
if (strpos($response, "Content-Type: application/xop+xml") !== false) {
//not using stristr function twice because not supported in php 5.2 as shown below
//$response = stristr(stristr($response, "<s:"), "</s:Envelope>", true) . "</s:Envelope>";
$tempstr = stristr($response, "<s:");
$response = substr($tempstr, 0, strpos($tempstr, "</s:Envelope>")) . "</s:Envelope>";
}
//log_message($response);
return $response;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment