Using PHP SOAP Client With GET Parameters in WSDL Address

Using PHP SOAP Client With GET Parameters in WSDL Address

The Problem:

Recently I was working on an integration with a SOAP based web service and the WSDL address required GET parameter for “id” to be passed in the WSDL. To my dismay, passing the PHP SOAP client constructor the WSDL address of was dropping the id parameter and I could not figure out why. There was nothing online I could find that described this problem.

Below is a stripped down version of how I was constructing the SOAP client

$wsdl = '';
$client = new SoapClient($wsdl);

Using $client->__getLastRequestHeaders() revealed that the POST address was being stripped down to without the id parameter.

The Solution:

After much troubleshooting I figured out that passing the “location” option to the constructor with the same WSDL defined again got the job done as seen below.

$wsdl = '';
$soapOptions = array(
'location' => $wsdl, // without this it will drop the GET params from the wsdl address
$client = new SoapClient($wsdl, $soapOptions);

Normally the “location” option is optional when using WSDL mode. That is fine if your WSDL address has no GET params. However without this workaround, the SOAP client strips the GET params from the address when posting your request to the SOAP service.