使用网上的例子
使用WCF头信息可以用于在调用Service的同时传递Header元数据

客户端:

            ChannelFactory<IOrderProcessor> channelFactory = new ChannelFactory<IOrderProcessor>("defaultEndpoint");
            IOrderProcessor orderProcessor = channelFactory.CreateChannel();

            //使用通道建立Scope
            using (OperationContextScope scope = new OperationContextScope(orderProcessor as IContextChannel))
            {
                MessageHeader
<string> mh = new MessageHeader<string>("abcde");
                MessageHeader header 
= mh.GetUntypedHeader("AuthKey"http://www.cjb.com/);//设置名称和命名空间
                OperationContext.Current.OutgoingMessageHeaders.Add(header);
               
orderProcessor.Function();//调用服务时发送的数据Header为在该OperationContextScope中设置的OperationContext
            }
服务端:
           //OperationContext.Current 返回当前建立连接的OperationContext
                
if (OperationContext.Current != null)
                {
                    authKey 
= OperationContext.Current.IncomingMessageHeaders.GetHeader<string>("AuthKey"http://www.cjb.com);
                }

使用网上的例子
使用WCF头信息可以用于在调用Service的同时传递Header元数据

客户端:

            ChannelFactory<IOrderProcessor> channelFactory = new ChannelFactory<IOrderProcessor>("defaultEndpoint");
            IOrderProcessor orderProcessor = channelFactory.CreateChannel();

            //使用通道建立Scope
            using (OperationContextScope scope = new OperationContextScope(orderProcessor as IContextChannel))
            {
                MessageHeader
<string> mh = new MessageHeader<string>("abcde");
                MessageHeader header 
= mh.GetUntypedHeader("AuthKey"http://www.cjb.com/);//设置名称和命名空间
                OperationContext.Current.OutgoingMessageHeaders.Add(header);
               
orderProcessor.Function();//调用服务时发送的数据Header为在该OperationContextScope中设置的OperationContext
            }
服务端:
           //OperationContext.Current 返回当前建立连接的OperationContext
                
if (OperationContext.Current != null)
                {
                    authKey 
= OperationContext.Current.IncomingMessageHeaders.GetHeader<string>("AuthKey"http://www.cjb.com);
                }

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-04
  • 2022-12-23
  • 2022-01-05
  • 2022-12-23
猜你喜欢
  • 2022-01-03
  • 2022-12-23
  • 2021-07-14
  • 2021-06-10
  • 2022-12-23
相关资源
相似解决方案