2013-05-08 70 views
0

是否可以通过某种方式将标题信息(或查询字符串)添加到wcf请求中? 我一直在瞎搞,像这样的IWcfPolicy了一下:IWcfPolicy - 动态地添加邮件标题

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(); 

这不然而工作。任何帮助都会非常困难。

回答

1

确定,所以这里是如何做到这一点:

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实现的方法。 因为此帖发现解决方案:how to add a custom header to every wcf call