1

如果服务器出现问题,我必须通过 HTTP 向另一个 Web 服务发送 SOAP 错误消息,所以我有以下代码:

  <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Body>
      <Response status="1">
        <Description>DESC</Description>
        <Errors>
          <Error>500</Error>
        </Errors>
      </Response>
    </soapenv:Body>
  </soapenv:Envelope>

这是格式正确的 SOAP 错误消息吗?

4

2 回答 2

3

这是格式正确的 SOAP 错误消息吗?

不,不是。它应该看起来像这样:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <soap:Fault>
         <faultcode>...</faultcode>
         <faultstring>...</faultstring>
         <detail>...</detail>
      </soap:Fault>
   </soap:Body>
</soap:Envelope>

SOAP 规范指定了故障是什么。你的看起来像某种错误结果对象,它有一些缺点,例如这里解释的。

如果您抛出异常,您的 WS 框架应该会正确生成错误。如果您没有使用框架而是以其他方式构建故障,那么它必须看起来像我上面的示例,否则不能称为 SOAP 故障。

于 2013-06-15T13:46:21.257 回答
0

嘿 Bogdan 我写了这段代码,就像一个魅力!

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
  <soap:Fault>
    <faultcode>500</faultcode>
    <faultstring>SERVER ERROR</faultstring>
    <detail>
      <Response_status>1</Response_status>
      <Description>DESCRIPTION</Description>
    </detail>
  </soap:Fault>
</soap:Body>
</soap:Envelope>

但是另一个问题是如何发送带有 http 代码 200 的 SOAP 成功消息,而且我还必须在消息中添加一些附加参数,这是其中的一部分

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<Response_status>0</Response_status>
<Description>SUCCESS</Description>
</soap:Body>
</soap:Envelope>

所以有了这个我也必须发送代码200,怎么写我可以这样写

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
  <soap:Fault>
    <faultcode>200</faultcode>
    <faultstring>OK</faultstring>
    <detail>
      <Response_status>0</Response_status>
      <Description>SUCCESS</Description>
    </detail>
  </soap:Fault>
</soap:Body>
</soap:Envelope>
于 2013-06-18T07:08:11.600 回答