Dec 15th, 2006, 11:32 AM
WSDL Faults - HTTP Error Codes
I wrote a WSDL with a binding soap over http.
In the WSDL I have defined fault elements.
When I have now an exception I can throw it and it will be converted into the defined fault element in the SOAPMessage.
This works all ok.
But now, when I look at the HTTP header I will see, that it will have the error code 500 Internal Server Error.
This seems to be correct(looking at the SOAP Spec), or when I read the WS-I Basic Profile:
"An INSTANCE MUST return a "500 Internal Server Error" HTTP status code if the response envelope is a Fault."
But what is the meaning of 500 Internal Server error?
The server encountered an unexpected condition which prevented it from fulfilling the request.
But what is with exceptions/faults which indicate something like "NoMoreSeats" or "NoSuchFlight"?
This is not a unexcpected condition.
Should we then not use the fault element of the WSDL?
Should we indicate them in the as simple element in the body?
In the airline sample application there is no fault definition in the WSDL for the exceptions NoMoreSeats/NoSuchFlight. But
when I force to throw them in the implementation I simply get an Ok(200) message with no data in the SOAPMessage body. Well
I think this is also not the expected behavior.
I come to the conclusion to not use the fault element for custom exceptions like
"NoMoreSeats" "NoSuchFlight". I simply define them as optinal elements in the body of the SOAPMessage. Then each
client has to implement his own behavior to throw them as exception..., the old way(defined as fault) it will throw them
What do you think? Should we use fault even if we indicate a 500 Internal Server Error?
Dec 16th, 2006, 06:00 AM
I guess it all comes down to the question what you consider a fault and what not. The WS-I Basic Profile is quite clear that if you do respond with a fault, you should set the status code to 500. The fact that the HTTP spec only uses this for "unexpected conditions" is not that important IMO, since HTTP is just the underlying transport protocol, and most SOAP client API's depend on the fact that 500=SOAP Fault.
The fact that there are no fault definitions in the airline WSDL has surprised more people, but this is simply due to the fact that fault definitions in WSDL only express the fault detail element (not codes nor fault strings), and the NoMoreSeats/NoSuchFlight faults do not contain details. I will try to make this clearer in the next version of the sample.
That said, you really should get a fault on the client side when you force the impementation to throw them. If not, it's a bug...
Dec 17th, 2006, 02:36 PM
Thanks for the answer.
So I maybe go with the 500, even if it goes against my feeling.
You are absolutly right. The fault is only the detail element. I have written such one for my application, so I was suprised I didn't see one in the airline example.
The airline example works perfect and sends a fault as you described. Sorry, my test was absolutly terrible...