SOAP Versions with SoapClient and WSClient

Saturday, January 12, 2008

With the PHP SOAP extension, you can use an option in the SoapClient constructor and set the SOAP version to be used.

$client = new SoapClient(null, array('location' => "http://localhost/soap.php",
'uri' => http://test-uri/,
'soap_version' => SOAP_1_2));

The above code sets SOAP 1.2 as the SOAP version to be used. The API document does not mention the default version used in case the user does not provide 'soap_version'. If you want SOAP 1.1, then use 'soap_version' => SOAP_1_1

With the PHP Web services framework, like in the case of SoapClient, you can use the WSClient constructor options to set the SOAP version to be used.

$client = new WSClient(array("to" => http://localhost/tutorial/soap/service.php,
"useSOAP" => 1.1));


The above code sets SOAP 1.1 as the SOAP version to be used. As the API document mentions, the default SOAP version used is SOAP 1.2, in case the user does not provide useSOAP option.



Interestingly, "useSOAP" => FALSE can be used as well.


$client = new WSClient(array("to" => http://localhost/tutorial/soap/service.php,


"useSOAP" => FALSE));

This means, instead of sending a SOAP message, send the payload given to the client as Plain Old XML. You can consider this to be a form of REST invocation.

No comments: