I am trying to call a method GetPDF which should return a PDF file. Output of this function is a Stream object through which the binary content of the PDF file is sent separately.
Default PHP client is not working here (at least was not working when I was doing 2 previous SOAP calls on different methods), so I have to use this extended class:
class MTOMSoapClient extends SoapClient {
public function __doRequest($request, $location, $action, $version, $one_way = 0) {
//echo $request;
$response = parent::__doRequest($request, $location, $action, $version, $one_way);
if (strpos($response, "Content-Type: application/xop+xml") !== false) {
//$response = stristr(stristr($response, "<s:"), "</s:Envelope>", true) . "</s:Envelope>";
$tempstr = stristr($response, "<s:");
$response = substr($tempstr, 0, strpos($tempstr, "</s:Envelope>")) . "</s:Envelope>";
/*echo "Response:<br />";
echo htmlspecialchars($response, ENT_QUOTES);*/
}
return $response;
}
}
The documentation says that I have to send 3 parameters: username, password and guid (it is returned in a response when I saved the contract, it looks like this 14169d56-2a3b-49e3-ada5-2c7002acee74)
I create the client:
$client = new MTOMSoapClient($urlWSDL, array('soap_version' => SOAP_1_1, 'trace' => 1));
Then I make a SOAP call like this:
try {
$result = $client->GetPDF('userName' => $userName, 'password' => $password, 'guid' => $GUID);
var_dump($res);
} catch (SoapFault $e) {
echo "<br />";
echo "SOAP EXCEPTION<br />";
echo $e;
} catch (Exception $e) {
echo "<br />";
echo "SOAP EXCEPTION<br />";
echo $e;
}
This gives me a error:
SOAP EXCEPTION
SoapFault exception: [Client] SOAP-ERROR: Encoding: Violation of encoding rules in /data/a/1/a11bb352-cec6-42c8-816d-f04af589cb8a/mywebsite.eu/web/soapcall.php:28 Stack trace: #0 /data/a/1/a11bb352-cec6-42c8-816d-f04af589cb8a/mywebsite.eu/web/soapcall.php(28): SoapClient->__call('GetPDF', Array) #1 {main}
I guess I am not retrieving the Stream object correctly, so the question is - How can I retrieve a Stream object, that contains binary content? I need to get it and then save it somewhere (on the server let's say).
Even when I do just $client->GetPDF(array('userName' => $userName, 'password' => $password, 'guid' => $GUID));
(without attaching it to some variable I get the same error). What does it mean that I'm "violating the encoding"? What can I do about it? How can I handle this Stream object?
I also tried calling the getLastRequest()
and getLastResponse()
functions but it didn't really output anything.