使域数据可用于 WCF 行为
在我的应用程序中,我有一个值(“BusinessUnit”),我想将其添加到对 Web 服务的每个请求中。一种方法是编写一个 WCF 行为,它会为我插入该值。
然而,我不清楚的一部分是如何从我的应用程序中获取这个值并融入到行为中。
为了说明我的问题,我将如何实现它。
public object BeforeSendRequest(ref Message request, IClientChannel channel)
{
string businessUnit = //How do I set this to a value known by the client?
MessageHeader<string> header =
new MessageHeader<string>(businessUnit);
request.Headers.Add(
header.GetUntypedHeader("Business Unit", "http://mywebsite.com"));
}
有什么想法吗?
In my application, I have a value ("BusinessUnit") which I want to add into every request to a web-service. One way of doing this would be to write a WCF behaviour, which would insert the value for me.
However, the one part I am not clear on is how I can get this value from my application and into the behaviour.
To illustrate my question, here is how I might implement it.
public object BeforeSendRequest(ref Message request, IClientChannel channel)
{
string businessUnit = //How do I set this to a value known by the client?
MessageHeader<string> header =
new MessageHeader<string>(businessUnit);
request.Headers.Add(
header.GetUntypedHeader("Business Unit", "http://mywebsite.com"));
}
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果所有调用的该值都相同,那么您可以考虑为其使用静态变量。如果每次调用都有所不同,您可以使用操作上下文来添加它(甚至跳过该行为),如下所示。
如果每个组调用都有所不同,您可以考虑将其传递给创建客户端时的行为,然后该行为可以将其传递给它创建的检查器:
If this value is the same for all calls, then you can consider using a static variable for it. If it varies per call, you can use the operation context to add it (and even skipping the behavior), as shown below
If it's something that varies per group of calls, you can consider passing it to the behavior when you create the client, and then the behavior can pass it to the inspector it creates: