IWcfPolicy-动态添加消息头 [英] IWcfPolicy - add message headers on the fly
本文介绍了IWcfPolicy-动态添加消息头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以即时将标头信息(或查询字符串)添加到wcf请求中? 我一直在像这样混乱IWcfPolicy:
Is it somehow possible to add header info (or querystrings) to a wcf request on the fly? I've been messing around a bit with the IWcfPolicy like this:
var xmlObjectSerializer = new DataContractSerializer(typeof(string));
var addressHeader = AddressHeader.CreateAddressHeader("client", "http://tempuri.org/", "someValue", xmlObjectSerializer);
var endpointAddress = new EndpointAddress(new Uri(url), new AddressHeader[] { addressHeader });
invocation.ChannelHolder.ChannelFactory.Endpoint.Address = endpointAddress;
invocation.Proceed();
但是,这不起作用.任何帮助将是非常感谢的.
this does not work however. Any help would be very much apperciated.
推荐答案
好的,这是操作方法:
using (var scope = new OperationContextScope((IContextChannel) (invocation.ChannelHolder.Channel)))
{
OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = new HttpRequestMessageProperty
()
{
Headers =
{
{"client", LicenseManager.Instance.GetCurrentLicense().LicenseKey}
}
};
invocation.Proceed();
}
此代码进入IWcfPolicy实现的Apply方法. 由于这篇文章找到了解决方案:如何添加自定义每个wcf调用的标头
This code goes into Apply method of the IWcfPolicy implementation. Found solution because of this post: how to add a custom header to every wcf call
这篇关于IWcfPolicy-动态添加消息头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文