代码之家  ›  专栏  ›  技术社区  ›  Max

如何从Web服务返回异常?

  •  4
  • Max  · 技术社区  · 14 年前

    <?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。根据soap模式,元素faultactor、faultcode、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/>
    

    我尝试过不同的topsoapdomconvert选项组合,但都没用。

    1 回复  |  直到 14 年前
        1
  •  0
  •   Max    14 年前

    我最后用了固定的方法TOPToSoapDomConvert.MakeFault文件. 有更好的解决办法吗?