0

I try to send header value from Jquery Ajax like this

$.ajaxSetup({
    url:http://my url
    headers: { "CustomHeader": "myValue" }
});

but i can't consume this header value in wcf service using C#..If there is any way to send custom header using ajax and retrieve same header in wcf service

Thanks in advance

Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331

1 Answers1

0

Using jQuery's ajax method, I will send headers like this:

$.ajax({       
    url: varUrl, // Location of the service  
    headers: {
        "Test": "Test-Value", // "Header-name" : "Header-value"          
    }       
});

In WCF, I will consume headers like this:

//retrieve your header value using "Header-name"...    
WebOperationContext current = WebOperationContext.Current;
WebHeaderCollection headers = current.IncomingRequest.Headers;
string Test= current.IncomingRequest.Headers.GetValues("Test")[0].ToString();
cokeman19
  • 2,405
  • 1
  • 25
  • 40