【问题标题】:IWcfPolicy - add message headers on the flyIWcfPolicy - 动态添加消息头
【发布时间】:2013-05-08 08:43:03
【问题描述】:

是否有可能以某种方式即时将标头信息(或查询字符串)添加到 wcf 请求中? 我一直在搞乱 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();

但这不起作用。任何帮助都会非常感激。

【问题讨论】:

    标签: castle-windsor wcffacility


    【解决方案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 实现的 Apply 方法。 因为这篇文章找到了解决方案:how to add a custom header to every wcf call

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-03-19
      • 2014-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多