As SOAP client returns XML response by default, I need to get JSON response in return instead of XML.
$client = new SoapClient(null, array('location' => "http://localhost/soap.php",
'uri' => "http://test-uri/"));
In that case what attribute needs to be set in SOAPClient or SOAPHeader so that it returns JSON response?
If your result is in PHP Array format, for example :
Then you can parse it to JSON using,
For detailed understanding, watch - https://www.youtube.com/watch?v=isuXO5Cv6Lg
SOAP supports only XML message format.
If the SOAP server you are trying to connect is a third party one to which you do not have direct access, you will have to convert the XML response to JSON after receiving, like this example here
If you want your web service server to support different data types like json, you need to look into RESTful web services.
From what I have been able to find out from some research, the SoapClient does not have any built in way to return the data directly as JSON (anyone else know if I'm wrong, it would save a heck of a lot of processing after the fact!) so you will probably need to take the XML returned data and parse it out manually.
I recalled that SimpleXMLElement offers some useful features, and sure enough, someone had some code snippets on php.net to do exactly that: http://php.net/manual/en/class.simplexmlelement.php