1

I have to send a SOAP fault message over HTTP to another web service if something goes wrong with a server, so I have this code:

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

Is this a properly formatted SOAP fault message?

Adam R. Grey
  • 1,861
  • 17
  • 30
CrBruno
  • 963
  • 8
  • 18
  • 33

2 Answers2

3

Is this a properly formatted SOAP fault message?

No it isn't. It should look something like this:

<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. Yours looks like an error result object of some sort which has some disadvantages as explained here for example.

Your WS framework should properly generate faults if you throw exceptions. If you are not using a framework but building the fault in some other way, then it must look like in my example above or it can't be called a SOAP fault.

Community
  • 1
  • 1
Bogdan
  • 23,890
  • 3
  • 69
  • 61
  • ok, but i still have to have a response status and description and also fault code so is is ok to make soap envelope like this: DESC ... ... ... – CrBruno Jun 17 '13 at 07:55
  • 1
    @CrBruno: If you send a fault, the SOAP `Fault` must appear directly inside the `Body`. If you have some custom information that you have to return with the fault then you must add that information inside the `detail` element of the fault. – Bogdan Jun 17 '13 at 17:49
0

Hey Bogdan I wrote this code and works like a charm!

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

But another question how to send a SOAP success message with a http code 200 an also I have to have some additional parameters in the message, this is a part of it

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

So with this also I have to send code 200, how to write that can I write it like this

<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>
CrBruno
  • 963
  • 8
  • 18
  • 33