tags:

views:

265

answers:

2

Is it possible to get the XML generated by SOAP Client before sending it to webservice?

I need this because response from webservice if one of parameters is really wrong I get errors like

Server was unable to read request. 
---> There is an error in XML document (2, 408). 
---> Input string was not in a correct format.

This typically includes firing up tcpmon or some other tcp watcher utility, capturing the webservice call, copy and paste xml to text editor and go to column 408 to see what's the problem.

I'd really like to simplify this process by getting the XML before sending it.

A: 

Hi,

Membrane monitor is like tcpmon, but you can block a request in the monitor than inspect it and when you are happy you can release the request. The monitor also features a XML beautifier that formats XML messages. I think we can also add a "Go To Line" function that addresses your problem in the next version. Membrane Monitor is open source and can be used for free.

baranco
Looks interesting but that takes me just one small step less than what I'm currenty doing.
Vnuk
+2  A: 

It is very, very hard (nigh impossible) to do that. What is much easier is using the SoapClient class' built-in debugging functionality to output the request after it has been sent. You can do that like so:

First, when creating your SOAPClient, enable tracing, like so:

$client = new SoapClient($wsdl, array('trace' => true));

Then do whatever processing is necessary to get ready to make the SOAP call and make it. Once it has been made, the following will give you the request you have just sent:

echo("<pre>"); //to format it legibly on your screen
var_dump($client->__getLastRequestHeaders()); //the headers of your last request
var_dump($client->__getLastRequest()); //your last request

And, if you want to see the response as well, the following should work:

var_dump($client->__getLastResponseHeaders()); //response headers
var_dump($client->__getLastResponse()); //the response
benjy
Getting that after sending request also works for me :) thanks a lot
Vnuk