WCF Typed Faults and Internal Server Error code 500?

孤人 提交于 2019-12-13 11:47:46

问题


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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/1070621/wcf-typed-faults-and-internal-server-error-code-500

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!