find a location for property in a new city

Wednesday, 16 March 2011

WCF REST: How to add a response header

I can't believe how difficult it is to add a response header to a response to a WCF REST service. It is so round the houses it really quite difficult.

Whatever happened to Response.Headers.Add from the friendly web code I'm so used to... Oh well, after scratching around for ages I finally found how:
var prop = new HttpResponseMessageProperty();
prop.Headers.Add("ApiVersion", "v1.0");
OperationContext.Current.OutgoingMessageProperties.Add(HttpResponseMessageProperty.Name, prop);

I know you're kicking yourself, right? "That's so obvious..." Ridiculous - I'm starting to thing WCF REST wasn't made with the developer in mind.


Actually, there is an easier way I found. Since this is in a REST service it is possible to use WebOperationContext which seems a lot more intuitive and concise:
WebOperationContext.Current.OutgoingResponse.Headers.Add("ApiVersion", "v1.0");


Follow britishdev on Twitter


  1. It's not that WCF REST wasn't made with the developer in mind; it's that WCF wasn't made with only REST in mind.

  2. If a cookie was going to be added to a header, how could it be set to expire after 30 days from current datetime?

  3. Motifz Designer Lawn. 1, 2 & 3 Piece Unstitched Premium Embroidered Lawn 2019, Premium embroidered Lawn, Premium lawn, Premium lawn 2019, Motifz, Premium lawn in Pakistan, Summer collection. Shipping worldwide. Stitching option available.

  4. I know you're kicking yourself, right? "That's so obvious..." Ridiculous - I'm starting to thing WCF REST wasn't made with the developer in mind. 4inkjets coupons


  5. شركة تنظيف الامارات

    شركة تنظيف دبي شركة نظافة بدبي
    شركة تنظيف كنب دبي بالبخار تنظيف كنب دبي بالبخار
    شركة غسيل سجاد بدبي غسيل سجاد دبي
    شركة تنظيف في ابوظبي شركات تنظيف ابوظبي
    شركة تنظيف منازل فى العين شركة تنظيف منازل العين
    شركات تنظيف كنب في ابوظبي شركات تنظيف كنب ابوظبي

  6. Great Article
    Cloud Computing Projects

    Networking Projects

    Final Year

    Projects for CSE

    JavaScript Training in Chennai


    Training in Chennai

    The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals,

    Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer.

    Angular Training

  7. Not everyone know all information about a celebrity and their net worth which changes every day according to their fame and investment but you can follow the info on celebrity heights which is available for everyone.

  8. Do your online grocery at Al-Fatah, Pakistan's best and largest online grocery website. Shop from a wide range of grocery including oil and ghee, tea and coffee, dry fruits and seeds, dairy and fresh bakery items, packaged foods, snacks and beverages, baby care, household essentials, fruits and vegetables and many more.

  9. Do you need Quick Loan to settle your bills and startup
    business? contact us now with your details to get a good
    Loan at a low rate of 2% per Annual
    Do you need Personal Finance?
    Business Cash Finance?
    Unsecured Finance
    Fast and Simple Finance?
    Quick Application Process?
    Finance. Services Rendered include,
    *Debt Consolidation Finance
    *Business Finance Services
    *Personal Finance services Help
    contact us for more information on how to get started:
    (Whats App) number:+919394133968
    please contact email id :
    Mr Sorina Jeffery