简体   繁体   中英

wcf events on client side

Is theres a client side event in wcf which get fired every time I create the object of my wcf client.

Actually I want to add outgoing header under wcf client

for now I am using code below in my client constructor under reference.cs

private void AddCustomHeaderUserInformation(OperationContextScope scope)
{
    MessageHeader<int> mhg = new MessageHeader<int>(10);
    MessageHeader untyped = mhg.GetUntypedHeader("slash", "slash");
    OperationContext.Current.OutgoingMessageHeaders.Add(untyped);
} 

There are two problems in using the above way

  1. every time I update the client with wcf ,code vanishes and I need to write it again
  2. code is suppose to be written in every client constructor, I am have 11 service contracts in my wcf. so it really sucks..

您应该看一下实现IClient MessageInspector的方法 -这允许您在较低级别插入服务模型层-您将在HeaderSendRequest中添加标头

我相信您可以在客户端上创建部分类,这样每次重新生成客户端代码时,行为就不会丢失。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM