2010-10-05 131 views
4

我使用THTTPSoapDispatcher和THTTPSoapPascalInvoker在Delphi中编写了一个简单的Web服务应用程序。一切工作正常,但我不明白如何处理异常。所以每当一个异常服务方法内发生时,产生了以下的SOAP响应:如何从Web服务返回异常?

<?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/"> 
<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> 

有没有有用的异常消息或错误代码。

如何处理异常,使得响应包含异常信息?

编辑:

多一点这个问题。要将异常转换为正确的SOAP响应,它应该是ERemotableException或此异常类的后代。问题是TSoapPascalInvoker(实际上是TOPToSoapDomConvert)无法生成正确的XML。据肥皂模式元素的顺序faultactor,Fault代码,Faultstring让人显著和TOPToSoapDomConvert将它们放置在一个不正确的顺序:

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

当它有望成为

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

我已经尝试不同的组合TOPToSoapDomConvert选项,但没有任何工作。

+2

您是否已经在WSDL中定义了您的异常并将它们绑定到相应的操作? – anirvan 2010-10-05 13:29:24

+2

不可以。我在Delphi中怎么做? – Max 2010-10-05 13:36:23

+0

检查http://en.wikipedia.org/wiki/Web_Services_Description_Language,例如带有“故障”定义的WSDL。接下来,我将尝试在Delphi中导入WSDL,并检查是否存在Fault类。 – mjn 2010-10-05 16:23:08

回答

0

我最终通过修复方法TOPToSoapDomConvert.MakeFault。有更好的解决方案吗?