More efficient ways of debugging SOAP based Web Services from PHP I have worked with SOAP services from time to time but now i have actually even nicer way to debug them. I still use SOAPUI as its an amazing tool but now i can easily see what is PHP doing :- )
Before, i would simply log everything in raw xml with headers etc. before i sent it out and whenever i got a response back i would log hat too. This is a great way to keep history of what was actually sent and what did we actually get back in case of any investigations etc. It does not impact the performance that much if your volumes of calls are low so you can even enable it temporarily on production servers to see what is there.
In my current workplace we have license for Charles (full featured web proxy) so i can use it to monitor soap activity. The advantages are huge as i can see everything that is happening. I can see what WSDL files are loaded, when, from what boxes etc. I can see what XSD files are included (it can be very difficult to debug broken web service that you have no control over if there are some XSD problems).
How to force all SOAP calls to go through proxy like Charles in PHP
PHP SoapClient can be configured to speak to all the services through a proxy. Its just not very clearly stated that all the 4 parameters have to be specified for that to work. So even if your proxy does not have user/pass you still need to provide them. At least that happened on my laptop.
So when you create a PHP SoapClient you have to pass all 4 proxy settings along with any additional options like this:
$client = new SoapClient("some.wsdl", array('proxy_host' => "localhost",
'proxy_port' => 8080,
'proxy_login' => "",
'proxy_password' => ""));
Running Charles web proxy on localhost for SOAP debugging
Then you run Charles, set it up to listen on the port you put in PHP code and there it is.
Every time PHP tries to call web service you will see sequence of calls and responses. You can use sequence view or hierarchical view. You can inspect messages on different layers like SOAP, XML, Headers, RAW. See below how Charles Web Proxy allows you to inspect SOAP messages as RAW, XML, SOAP, it will also allow you to inspect headers of both request and response. Can you ask for more?!

Don't forget to clear PHP tmp folder when your WSDL contract changes
PHP SoapClient will cache WSDL and XSD Schema files so every time your service changes you have to clear tmp folder so that PHP SoapClient would download WSDL and XSD files all over again.

You can see here sequence of WSDL and XML Schema files downloaded by PHP SoapClient. You will see where are they downloaded from and you will see errors if there are any. It can be very difficult to figure out what is wrong if some XSD file is not loading because it is in different host name etc. Charles proxy will save hours of confusion : -)
Summary
SOAPUI is awesome and logging external calls and responses is still useful but ability to instantly see all the traffic is unbeatable :- ). I recommend combining all these tools to have a full image of what is happening, what was happening and to easily test web services.
Comments
Post new comment