【发布时间】:2015-01-22 14:56:46
【问题描述】:
我正在 Delphi 2007 中编写一个 SOAP 客户端来进行简单的海关放行检查。我向 SOAP 服务器发送了一些信息,如果服务器找不到我发送的信息,我应该收到有关海关放行的详细信息或 SOAP 故障。第一部分工作正常,但故障处理却不行。 WSDL 指定了一个自定义 SOAP 异常(这包含在主 WSDL 中 - 整个 WSDL 没有显示):
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsd:schema targetNamespace="http://trips.crownagents.com/wsexception/message"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://trips.crownagents.com/wsexception/message">
<xsd:element name="WSException" type="WSException" nillable="true"/>
<xsd:complexType name="WSException">
<xsd:sequence>
<xsd:element name="ErrorCode" type="xsd:string" minOccurs="0" maxOccurs="1"/>
<xsd:element name="ErrorDescription" type="xsd:string" minOccurs="0" maxOccurs="1"/>
<xsd:element name="Stack" type="xsd:string" minOccurs="0" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
我得到的 SOAP 响应似乎引用了异常:
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns: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:ns0="http://trips.crownagents.com/wsexception/message"
xmlns:ns1="http://trips.crownagents.com/external/customs/release/message"
xmlns:ns2="http://trips.crownagents.com/external/common/message">
<env:Body>
<env:Fault xsi:type="env:Fault">
<faultcode>env:Server</faultcode>
<faultstring xsi:nil="1"/>
<detail>
<ans1:WSExceptionResponse xmlns:ans1="http://msgsvr.trips.crownagents.com/">
<ErrorCode>0002</ErrorCode>
<ErrorDescription>Invalid Declaration</ErrorDescription>
<Stack>getSingleResult() did not retrieve any entities.</Stack>
</ans1:WSExceptionResponse>
</detail>
</env:Fault>
</env:Body>
</env:Envelope>
但是,我的代码永远不会看到 WSExceptionResponse。相反,我得到了一个通用的 ERemotableException:
Try
Res := Rel.releaseStatus(RelInfo);
Except
On E: WSExceptionResponse Do // This never fires
Status('Release check error (' + E.ErrorCode + ' - ' +
E.ErrorDescription + ').', True);
Else
Status('Release check error (' + Exception(ExceptObject).Message +
').', True);
End;
我已阅读到 Delphi 2007 (https://groups.google.com/forum/#!msg/borland.public.delphi.webservices.soap/71t3P-vPMbk/qw9JVTEVS3YJ) 中的 SOAP 处理存在一些问题,我已更改 OPToSOAPDomConv.pas 文件以根据建议恢复它,但这无济于事。有没有人知道我可能做错了什么?
【问题讨论】:
-
使用 SoapUI 验证服务是否按预期工作,然后检查 SoapUI 和 Delphi SOAP 请求之间是否存在差异。
-
SoapUI 发送消息的方式与 Delphi 发送消息的方式完全不同(尽管主要与命名空间有关),但返回的错误消息完全相同。
标签: web-services delphi soap wsdl delphi-2007