c# - Header in MessageInspector is not being updated -


i'm trying implement message interceptor in various wcf services. goal track every call being made between these services since first call client made. i'm trying attach counter in header know how many services being called. in inspector class, in afterreceiverequest method, check if header has property counter, if has it, add one, , if not set value one.

in approach encountered 2 problems: 1. in second call service, when afterreceiverequest being called, property in header never there, being set there 1 again. 2. in beforesendreply i'm trying update value in header, enddate current date, value neither being returned :-/

i don't know if i'm setting header wrong. header in second call should same, right?

this inspector class

public class logmessageinspector : idispatchmessageinspector {     #region implementacion de idispatchmessageinspector      public object afterreceiverequest(ref message request, iclientchannel channel, instancecontext instancecontext)     {                     try         {             loggercontext lc = new loggercontext();             var currentloggercontext = trygetheader<loggercontext>("loggercontext", "http://tempuri.org");              if (currentloggercontext == null || currentloggercontext == default(loggercontext))             {                 lc.trackingno = 1;                 lc.startdate = datetime.now;             }             else             {                 lc.startdate = currentloggercontext.startdate;                 lc.trackingno = lc.trackingno + 1;                  operationcontext.current.outgoingmessageheaders.removeall("loggercontext", "http://tempuri.org");             }              messageheader messageheader = messageheader.createheader("loggercontext", "http://tempuri.org", lc);             operationcontext.current.outgoingmessageheaders.add(messageheader);          } catch (exception ex) {          }          return null;     }      public void beforesendreply(ref message reply, object correlationstate)     {         var currentloggercontext = trygetheader<loggercontext>("loggercontext", "http://tempuri.org");         if (currentloggercontext != null)         {             loggercontext lc = new loggercontext();              lc.enddate = datetime.now;             lc.trackingno = currentloggercontext.trackingno;             lc.startdate = currentloggercontext.startdate;              operationcontext.current.outgoingmessageheaders.removeall("loggercontext", "http://tempuri.org");             messageheader messageheader = messageheader.createheader("loggercontext", "http://tempuri.org", lc);             operationcontext.current.outgoingmessageheaders.add(messageheader);         }     }      #endregion      private static t trygetheader<t>(string name, string sn)     {         try          {             return operationcontext.current.outgoingmessageheaders.getheader<t>(name, sn);         }         catch         {             return default(t);         }     } } 

the loggercontext is

public class loggercontext  {     public int trackingno { get; set; }      public datetime startdate { get; set; }      public datetime enddate { get; set; }  } 

any appreciated :)


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -