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.
ok so here's how to do it:
using (var scope = new OperationContextScope((IContextChannel) (invocation.ChannelHolder.Channel)))
{
OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = new HttpRequestMessageProperty
()
{
Headers =
{
{"client", LicenseManager.Instance.GetCurrentLicense().LicenseKey}
}
};
invocation.Proceed();
}
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