询问者
WCF 3.5中自定义REST服务的错误处理器时如何给客户端返回500错误。

问题
-
我给一个REST服务实现定义了一个错误处理器:
internal sealed class SearchingErrorHandler : IErrorHandler { #region IErrorHandler 成员 public bool HandleError(Exception error) { return true; } public void ProvideFault(Exception error, MessageVersion version, ref Message fault) { var detail = error.Message; fault = Message.CreateMessage(version, "", detail, new DataContractSerializer(detail.GetType())); var webBodyFormatMessageProp = new WebBodyFormatMessageProperty(WebContentFormat.Xml); fault.Properties.Add(WebBodyFormatMessageProperty.Name, webBodyFormatMessageProp); var httpResponseMessageProp = new HttpResponseMessageProperty(); httpResponseMessageProp.Headers[HttpResponseHeader.ContentType] = Utility.XmlContentType; httpResponseMessageProp.StatusCode = HttpStatusCode.InternalServerError; httpResponseMessageProp.StatusDescription = error.Message; fault.Properties.Add(HttpResponseMessageProperty.Name, httpResponseMessageProp); } #endregion }
是通过这种方式加入的:
[ErrorHandlerBehavior(typeof(CachedErrorHandler))] internal sealed class CachedPageService : ICachedPage
调试的时候,如果服务抛出异常,流程能走到ProvideFault方法中,能够正常调用,一切都好像正常,但是客户端收到的始终是400错误,而不是500.
问题出在哪?
快乐在于能够长时间的为自己认为值得的事情努力工作,不管它是什么。
全部回复
-
你这个客户端 URL 参数 正确吗?
Frank Xu Lei--谦卑若愚,好学若饥
专注于.NET平台下分布式应用系统开发和企业应用系统集成
Focus on Distributed Applications Development and EAI based on .NET
【老徐的网站】:http://www.frankxulei.com/
-
WebServiceHost支持WCF的Rest编程模型
你修改一下 重新测试一次~
Frank Xu Lei--谦卑若愚,好学若饥
专注于.NET平台下分布式应用系统开发和企业应用系统集成
Focus on Distributed Applications Development and EAI based on .NET
【老徐的网站】:http://www.frankxulei.com/