我尝试像这样从Jquery Ajax发送头值
$.ajaxSetup({
url:http://my url
headers: { "CustomHeader": "myValue" }
});
但我无法使用C#在wcf服务中使用此标头值。如果有任何方法使用ajax发送自定义标头并在wcf服务中检索相同的标头
提前致谢
答案 0 :(得分:0)
Using "Jquery Ajax" i will send headers like ..
$.ajax({
url: varUrl, // Location of the service
headers: {
"Test": "Test-Value", // "Header-name" : "Header-value"
}
});
In "Wcf" I will consume headers like..
//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();