c# - WCF ServerInspectorBehavior - How to keep a header in AfterReceiveRequest to use in BeforeSendReply -
i have wcf service have extended behavior.
this code:
public object afterreceiverequest(ref message request, iclientchannel channel, instancecontext instancecontext) { if (logger.isinfoenabled) { // header sent client need keep can return in beforesendreply var securitytoken = request.headers.getheader < string > (request.headers.findheader("token-id", "securityinfo")) var bufferedcopy = request.createbufferedcopy(int.maxvalue); var sizelog = string.format("request message size: ~{0} kb", getmessagelengthinkb(bufferedcopy.createmessage())); logger.info(sizelog); request = bufferedcopy.createmessage(); } return null; } public void beforesendreply(ref message reply, object correlationstate) { if (logger.isinfoenabled) { // here want securitytoken value ??? var bufferedcopy = reply.createbufferedcopy(int.maxvalue); var sizelog = string.format("response message size: ~{0} kb", getmessagelengthinkb(bufferedcopy.createmessage())); logger.info(sizelog); reply = bufferedcopy.createmessage(); } }
any clue on how can keep securitytoken variable can use before sending reply client?
you can return token in afterreceiverequest method (instead of returning null) , passed beforesendreply correlationstate object (cast appropriate type , can use it)
Comments
Post a Comment