5

Here is my response envelope:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <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">
               <ReasonCollection xmlns:a="http://schemas.datacontract.org/2004/07/Zagat.Enterprise.Domain"/>
               <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

John Saunders
  • 160,644
  • 26
  • 247
  • 397
DDiVita
  • 4,225
  • 5
  • 63
  • 117
  • Are you getting that message in a ProtocolException? I had an issue with those exceptions cause I always got the html code in the exception message. Now I just asume that every protocol exception comes with this html code and I parse it to get the real message. http://stackoverflow.com/questions/998065/does-system-servicemodel-protocolexception-always-have-html-code-in-its-message – sebagomez Jul 01 '09 at 18:30

2 Answers2

5

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.

Eugene Yokota
  • 94,654
  • 45
  • 215
  • 319
  • Sure, but if you make it a 200, will the clients even recognize it? – John Saunders Jul 01 '09 at 18:44
  • 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. – Eugene Yokota Jul 01 '09 at 20:49
  • 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 Jul 02 '09 at 01:04
  • 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. – Eugene Yokota Jul 02 '09 at 03:23
  • Part 2 of the spec is part of the spec, and it specifies the bindings! – John Saunders Jul 03 '09 at 02:18
  • 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.' – Eugene Yokota Jul 03 '09 at 07:18
  • @eed3si9n: The entire binding is optional - not pieces of it. – John Saunders Jul 10 '09 at 12:42
1

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
  • 160,644
  • 26
  • 247
  • 397