Tracing SOAP Messages

Tuesday, January 8, 2008

With WSO2 Web services framework for PHP, you can trace the SOAP messages that are sent and received by the client.

The Web services client class, WSClient has two methods for this, getLastRequest() and getLastResponse().

After calling the request() method of the client instance, you can call any of those methods to gain access to the messages.

 

$response = $client->request($reqestPayloadString);

printf("<br/> Request = %s </br>", htmlspecialchars($client->getLastRequest()));

printf("<br/> Response = %s </br>", htmlspecialchars($client->getLastResponse()));

 

The above code fragment would display the request and the response messages that were sent and received as a result of the call to the request() method.

An example output would look something like:

Request = <soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Header/><soapenv:Body><getFactorial> <param>6</param> </getFactorial></soapenv:Body></soapenv:Envelope>
Response = <soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Header/><soapenv:Body><getFactorialResponse> <result>720</result> </getFactorialResponse></soapenv:Body></soapenv:Envelope>

 

Tracing of SOAP messages in relation to a service invocation is useful specially when troubleshooting services and clients.

No comments: