I used Wireshark to capture what my browser was sending to a printer and captured this:
I'm trying to duplicate that in PHP with the SOAP extension and am having some difficulty. Here's my PHP code:
<?php
$client = new SoapClient(dirname(__FILE__) . '/WebPackage/WSDPrinterService.wsdl', ['trace' => 1]);
$client->__setLocation('http://192.168.1.116/WebServices/PrinterService');
$temp = new stdClass();
$temp->DocumentId = 1;
$temp->Compression = 'none';
$temp->Format = 'unknown';
$params = new stdClass();
$params->JobId = 1;
$params->DocumentDescription = $temp;
$params->LastDocument = true;
$params->DocumentData = file_get_contents('filename.pdf');
$client->SendDocument($params);
Here's the error I get:
[30-Dec-2021 12:57:15 America/Chicago] PHP Fatal error: Uncaught SoapFault exception: [] in /home/neubert/test.php:16
Stack trace:
#0 /home/neubert/test.php(16): SoapClient->__call('SendDocument', Array)
#1 {main}
thrown in /home/neubert/test.php on line 16
If I put $client->SendDocument($params)
in a try / catch block and do $client->__getLastRequest()
/ $client->__getLastResponse()
I can see the request (https://pastebin.com/9mTEBD2y) / response (https://pastebin.com/ue94kQUZ).
The faultcode part of the response says "SOAP-ENV:VersionMismatch" but the faultstring makes it sound like there could be something else wrong with the request other than just the version. None-the-less I tried to change the SOAP version by adding 'soap_version' => SOAP_1_2
(and SOAP_1_1) to the ['trace' => 1]
array. With SOAP_1_2 the request (https://pastebin.com/cZGusCXa) / response (https://pastebin.com/PLfTV8qt) changes a bit as does the error (End of file or no input: Operation interrupted or timed out) but it's still not working and the error is still just as cryptic to me.
The only thing I can figure is that the DocumentData isn't being formatted correctly. Here's the DocumentData part of the good SOAP request:
<pri:DocumentData>
<xop:Include href="cid:0@body"></xop:Include>
</pri:DocumentData>
Here's the DocumentData of hte bad SOAP request:
<ns1:DocumentData>...</ns1:DocumentData>
So maybe that's the issue? If so then it's not clear to me how to make PHP use xop:Include for the attachment.
The WSDL can be found at https://learn.microsoft.com/en-us/windows-hardware/drivers/print/ws-print-v1-1 (do Ctrl + F and find "Print Device Definition V1.0 for Web Services on Devices")
edit: I also tried converting the PDF to a PS as well but that didn't help. I thought that might make a difference because https://learn.microsoft.com/en-us/previous-versions/ff562064(v=vs.85) describes DocumentData as "Document PDL Data" and https://stackoverflow.com/a/39708917/569976 mentions PS and PCL as PDL's but not PDF.