原来忘记在哪个大牛的博客上看到的,说添加顺序与执行顺序是相反的,事实在下边:直接上代码:
//STEP10,不论如何先记录下来请求信息 if (msgHandlerSettings.LoggingHandlerConfig.Enable) { config.MessageHandlers.Add(new LoggingHandler( _CreateInstance(msgHandlerSettings.LoggingHandlerConfig.LoggingRepositoryType) as ILoggingRepository)); } //STEP11,检查数据在传输过程中是否被篡改 if (msgHandlerSettings.SignHandlerConfig.Enable) { config.MessageHandlers.Add(new SignHandler()); } //STEP12,请求数据转化成标准JSON格式 if (msgHandlerSettings.ContentParserHandlerConfig.Enable) { config.MessageHandlers.Add(new ContentParserHandler( _CreateInstance(msgHandlerSettings.ContentParserHandlerConfig.ContentParserType) as IContentParser)); }
程序输出:
Req___LoggingHandler Begin
Req___LoggingHandler End
Req___SignHandler
Begin
Req___SignHandler End
Req___ContentParserHandler
Begin
Req___ContentParserHandler
End
..............................................................
Res___ContentParserHandler
Begin
Res___ContentParserHandler End
Res___SignHandler
Begin
Res___SignHandler End
Res___LoggingHandler
Begin
Res___LoggingHandler End
线程 ‘<无名称>‘ (0x1cf0) 已退出,返回值为 0
(0x0)。
程序“[1420] iisexpress.exe: 托管(v4.0.30319)”已退出,返回值为 0
(0x0)。
程序“[1420] iisexpress.exe: 程序跟踪”已退出,返回值为 0 (0x0)。