SOAP错误消息

时间:2013-06-14 11:19:15

标签: c# xml soap

如果服务器出现问题,我必须通过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错误消息吗?

2 个答案:

答案 0 :(得分: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>

The SOAP specification specifies what a fault is。你的看起来像某种has some disadvantages as explained here的错误结果对象。

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

答案 1 :(得分:0)

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

<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>