tags:

views:

1694

answers:

2

Here is my response envelope:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt;
   <s:Body>
      <s:Fault>
         <faultcode>s:Client</faultcode>
         <faultstring xml:lang="en-US">The creator of this fault did not specify a Reason.</faultstring>
         <detail>
            <ServiceFault xmlns="http://schemas.datacontract.org/2004/07/Zagat.Services.FaultException" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"&gt;
               <ReasonCollection xmlns:a="http://schemas.datacontract.org/2004/07/Zagat.Enterprise.Domain"/&gt;
               <ReasonMessage>Credentials are not valid</ReasonMessage>
            </ServiceFault>
         </detail>
      </s:Fault>
   </s:Body>
</s:Envelope>
enter code here

Here is my Header:

HTTP/1.1 500 Internal Server Error
Date: Wed, 01 Jul 2009 17:55:33 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Cache-Control: private
Content-Type: text/xml; charset=utf-8
Content-Length: 564

How can I get IIS to return a 200 instead of a 500? My code runs on the server, I am just sending a fault to the client to process.

Daniel

A: 

My recollection of the SOAP Protocol is that faults are to be sent as code 500.

Faults are not success responses. They indicate the nature of the failure.

John Saunders
+1  A: 

You can easily customize error handling of WCF. See Modifying HTTP Error Codes, Part 1 and Part 2 by Nicholas Allen's Indigo Blog; WCF: Throwing Exceptions With WebHttpBinding by Andre de Cavaignac; and Exception Handling in WCF Web Service by Brajendra Singh.

eed3si9n
Sure, but if you make it a 200, will the clients even recognize it?
John Saunders
I've seen options in other framework that lets you choose between 500 and 200. I think it was Delphi's SOAP. When I did the error handling, I was making a service that works as SOAP and REST, so I was doing 500 for SOAP and 401,403,404,etc for REST.
eed3si9n
Ok, but did you return a SOAP fault for REST? Return what you like for REST, but the SOAP protocol limits which HTTP codes can be used under which circumstances. If you want to return something that _looks_ more or less like a SOAP Fault, but not _be_ one, then catch the exception and just return your own custom XML. But if you expect the client to see your SOAP fault as a SOAP Fault, you need to use the correct status code.
John Saunders
I did POX or JSON for REST. SOAP protocol itself is a messaging framework, so it doesn't specify HTTP status. You could use email or pigeon to carry SOAP messages. http://www.w3.org/TR/soap12-part1/ The part that specifies 500 is SOAP HTTP Binding in part 2 of the spec: http://www.w3.org/TR/soap12-part2/#soapinhttp. I certainly wouldn't recommend using 500, but if @DDiVita wants to do it, it's up to him. It may be necessary because some platform, including .NET 2.0 IIRC, loses the response message body. FaultException(TDetail) is a .NET 3.x feature.
eed3si9n
Part 2 of the spec is part of the spec, and it specifies the bindings!
John Saunders
It depends. The first thing SOAP HTTP binding talks about is that it's optional. See 7.1.1 Optionality: The SOAP HTTP Binding is optional and SOAP nodes are NOT required to implement it. A SOAP node that correctly and completely implements the SOAP HTTP Binding may to be said to 'conform to the SOAP 1.2 HTTP Binding.'
eed3si9n
@eed3si9n: The entire binding is optional - not pieces of it.
John Saunders