REST WCF 服务在 HEAD 中发送错误 500,而不是未找到 404

  • 本文关键字:错误 服务 WCF HEAD REST wcf rest iis
  • 更新时间 :
  • 英文 :


这是我的问题,我有一段WCF REST代码,如果在这种情况下找不到图像的请求对象,则按照建议返回NULL。 这是我的代码

if (imageStream == null) {
 WebOperationContext.Current.OutgoingResponse.SetStatusAsNotFound("Image not available for the requested size.");
 return null;
}

这在 GET 中按预期发送 404 错误,但对于 HEAD 发送 500 内部服务器错误

有什么想法吗?

尝试使用 throw new WebFaultException(HttpStatusCode.NotFound); 以下是有关 WebFaultException 的更多信息

最新更新