Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF REST list HTTP headers on incoming request

Tags:

rest

wcf

I've fired up the WCF REST starter kit and am trying to access the HTTP headers on the incoming request. I've looked at OperationContext.Current.IncomingMessageHeaders but either it doesn't hold them or I'm accessing it wrong.

How do I list the HTTP headers?

like image 321
sipsorcery Avatar asked Oct 20 '09 09:10

sipsorcery


1 Answers

Eventually found the answer.

using System.ServiceModel.Web;

protected override IEnumerable<KeyValuePair<string, SampleItem>> OnGetItems() {
    WebHeaderCollection headers = WebOperationContext.Current.IncomingRequest.Headers;
    foreach (string key in headers.Keys) {
        logger.Debug("header " + key + "=" + headers[key]);
    }
}
like image 51
sipsorcery Avatar answered Nov 04 '22 18:11

sipsorcery