如何从wcf服务中找不到404?

Bre*_*eak 3 .net wcf http-status-code-404

曾经,为了完全控制HTTP消息的头部/主体 - 我使用Message类.例如,要返回一些XML,我会调用

  public Message ShowRunResults()
  {
    // some [OperationContract] implementation
    webContext.CreateTextResponse(result.ToString(), "application/xml", Encoding.ASCII);
  }
Run Code Online (Sandbox Code Playgroud)

问题是如何返回404未找到或其他HTTP代码?非常感谢

小智 5

使用WebOperationContext.Current.OutgoingResponse,您可以设置HTTP代码和状态.