I'm trying to make a SOAP request to a local printer endpoint - http://192.168.1.116/WebServices/PrinterService . Normally to get the WSDL that corresponds to the endpoint you tack on ?wsdl
to the end of the URL but in this case that isn't working.
Thankfully the WSDL is available for download from https://docs.microsoft.com/en-us/windows-hardware/drivers/print/ws-print-v1-1 . As such I'm able to read it from the local filesystem thusly:
$client = new SoapClient(dirname(__FILE__) . '/WebPackage/WSDPrinterService.wsdl', ['trace' => 1]);
$client->SendDocument();
The problem is that this code always errors out with the following:
[29-Dec-2021 14:39:11 America/Chicago] PHP Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host in /home/neubert/test.php:9
Stack trace:
#0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'http://localhos...', 'http://schemas....', 1, 0)
#1 /home/neubert/test.php(9): SoapClient->__call('SendDocument', Array)
#2 {main}
thrown in /home/neubert/test.php on line 9
The second parameter of __doRequest
($location
) is 'http://localhos...'. That's most likely localhost being truncated.
My question is... how do I make it so that WSDL's that live on the local filesystem don't always post to localhost?
I did grep -r localhost .
in the WebPackage directory and replaced all those instances with 192.168.1.116 and am still getting the error.
Any ideas?
CodePudding user response:
The SoapClient will use the address within the WSDL to make calls. There should be something like:
<soap:address location="http://localhost...etc..."/>
or
<soap12:address location="http://localhost...etc..."/>
in your WSDL file. The XML prefixes may be different but you should have one or two addresses there. Replace this address with the one where you want your client to make calls to.
Another thing to try might be to set a location for the call:
$client = new SoapClient(dirname(__FILE__) . '/WebPackage/WSDPrinterService.wsdl', ['trace' => 1]);
$client->__setLocation('http://192.168.1.116/WebServices/PrinterService');
and see if that works.