简体   繁体   English

避免为WCF中的每个请求添加自定义标题?

[英]Avoid Adding Custom Headers for every request in WCF?

I had a wcf service, provided by one of our team which need to be authenticated every time from SoapHeader as 我有一个wcf服务,由我们的一个团队提供,每次需要从SoapHeader进行身份验证为:

scope = new OperationContextScope(objVendorServiceClient.InnerChannel);
header= MessageHeader.CreateHeader("Token", "NameSpace", Session["Token"]);
OperationContext.Current.OutgoingMessageHeaders.Add(header);

AFAIK, as HTTP is Stateless Protocol, i need to add these lines everytime for every request. AFAIK,因为HTTP是无状态协议,我需要每次为每个请求添加这些行。 But as per the requirement, i should not call these (either in a function or directly) for every request explicitly in my code. 但是按照要求,我不应该在代码中显式地为每个请求(在函数中或直接)调用它们。 So what i am planning to do is, by adding HTTPHANDLER, before sending Request can we add these custom headers to actual request through HTTP?. 所以我打算做的是通过添加HTTPHANDLER,在发送请求之前,我们可以通过HTTP将这些自定义标头添加到实际请求中吗? If yes could any one give me a suggestion on this? 如果可以的话,有人可以给我一个建议吗?

Finally with the help of Leo Tang, i achieved this. 最终,在李小龙的帮助下,我实现了这一目标。 He suggested me to use Message Inspectors which worked as a champ. 他建议我使用作为冠军的Message Inspectors。 Please find the link for further reference 请找到链接以获取更多参考

http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/4da32c89-b839-49af-805a-69e85bffecd8 http://social.msdn.microsoft.com/Forums/zh-CN/wcf/thread/4da32c89-b839-49af-805a-69e85bffecd8

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM