1

I need to access the HTTP response headers that are to be returned to the client from a WCF Service. Accessing the HTTPContext is easy(through HttpContext.Current.Response), but what is the event/extension/behavior that is executed lastly, when the StatusCode is already set (for ex. if the status is 500)?

EDIT: Message Inspectors don't seem to be a good solution here, because at the time they run, the status code isn't set yet. (At least in my trial that was the case)

4

2 に答える 2

1

WebOperationContext.Current.IncomingRequest次のように、 のすべてのヘッダーにアクセスできます。

IncomingWebRequestContext request = WebOperationContext.Current.IncomingRequest;
WebHeaderCollection headers = request.Headers;

Console.WriteLine("-------------------------------------------------------");    
foreach (string headerName in headers.AllKeys)
{
  Console.WriteLine(headerName + ": " + headers[headerName]);
}
Console.WriteLine("-------------------------------------------------------");

こちらをご覧ください

于 2015-06-23T14:20:43.763 に答える
0
  1. ヘッダーを制御する最も簡単な方法は、メッセージ コントラクトを使用することです。

  2. Message Inspectorsを使用して、サービス側でメッセージを受信した直後にメッセージを監視します。

  3. 他の標準ルートに満足できない極端なケースでは、未加工の XML メッセージを扱う POX (Plain Old XML) タイプの操作を使用できます。

于 2011-07-25T18:46:31.810 に答える