如何在 WCF 中为每次调用添加带有动态用户值的 cutom 标头? [英] How add cutom header in WCF with dynamic user values to every call?
问题描述
我正在使用 WCF 客户端使用一个 java web 服务.我想将用户相关信息传递给标题中的服务.我已经通过线程如何为每个 WCF 调用添加自定义标头?
I am consuming one java webservice with WCF client. I want to pass user related information to service in header. I have aleady gone to through thread How to add a custom header to every WCF calls?
我已经使用 BeforeSendRequest
() 方法实现了 IClientMessageInspector
接口.现在,我想在像 Oraganization 这样的 SOAP 标头中传递用户相关信息,每个用户可能会有所不同.我在使用此服务的 ASP.net 应用程序中拥有所有这些信息.
I have implemented IClientMessageInspector
interface with BeforeSendRequest
() method. Now, I want to pass user related information in SOAP header like Oraganization, which may differ for every user. I have all this information in my ASP.net application, which uses this service.
无论如何我可以将用户相关信息从asp.net会话传递给这个BeforeSendRequest
()方法并在发送任何请求之前构建消息头?
Is there anyway I can pass user related information to this BeforeSendRequest
() method from asp.net session and build Message header before sending any request?
推荐答案
选择不多
- 将信息放入
Session
并在BeforeSendRequest
中检索 - 将其放入
HttpContext.Current.Items
并在 `BeforeSendRequest' 中检索它 - 使用线程本地存储 (http://msdn.microsoft.com/en-us/library/6sby1byh.aspx)
- Put the information in
Session
and retrieve it inBeforeSendRequest
- Put it in
HttpContext.Current.Items
and retrieve it in `BeforeSendRequest' - Use Thread Local Storage (http://msdn.microsoft.com/en-us/library/6sby1byh.aspx)
这篇关于如何在 WCF 中为每次调用添加带有动态用户值的 cutom 标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!