views:

93

answers:

1

I've written a simple web servrice application in Delphi using THTTPSoapDispatcher and THTTPSoapPascalInvoker. Everything works ok, except that I don't understand how to handle exceptions. So whenever an exception occurs inside the service method, the following SOAP response is generated:

<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"&gt;
 <SOAP-ENV:Body>
  <SOAP-ENV:Fault>
  <faultactor/>
   <faultcode>SOAP-ENV:Server</faultcode>
   <faultstring>Error Message</faultstring>
  </SOAP-ENV:Fault>
 </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

There's no useful exception message or error code.

How do I handle exceptions in such a way that the response includes the exception info?

EDIT:

Little more on this problem. For the exception to be translated into a correct SOAP response it should be either ERemotableException or a descendant of this exception class. The problem is that TSoapPascalInvoker (actually TOPToSoapDomConvert) fails to generate a correct XML. According to soap schema the order of elements faultactor, faultcode, faultstring is significant and TOPToSoapDomConvert place them in an incorrect order:

<faultactor/>
<faultcode>SOAP-ENV</faultcode>
<faultstring>This is my Error Message</faultstring>

when it is expected to be

<faultcode>SOAP-ENV</faultcode>
<faultstring>This is my Error Message</faultstring>
<faultactor/>

I've tried different combinations of TOPToSoapDomConvert options but nothing worked.

A: 

I ended up by fixing method TOPToSoapDomConvert.MakeFault. Is there a better solution?

Max