Example #1
0
        public void BeforeSendReply(ref Message reply, object correlationState)
        {
            try
            {
                var clientContext = new ClientApplicationContext();
                clientContext.ServerMachineIP = CommonConfiguration.MachineIP;
                clientContext.RequestIdentity = ServerApplicationContext.Current.RequestIdentity;
                clientContext.ServerExceptionID = ServerApplicationContext.Current.ServerExceptionID ?? "";

                var serviceType = OperationContext.Current.GetCurrentServiceDescription().ServiceType;
                if (!serviceVersionCache.ContainsKey(serviceType.FullName))
                {
                    lock (locker)
                    {
                        if (!serviceVersionCache.ContainsKey(serviceType.FullName))
                        {
                            serviceVersionCache.Add(serviceType.FullName, serviceType.Assembly.GetName().Version.ToString());
                        }
                    }
                }
                clientContext.ServerVersion = serviceVersionCache[serviceType.FullName];

                reply.SetApplicationContext(clientContext);

                var setting = WcfSettingManager.CurrentServerSetting(OperationContext.Current.GetCurrentServiceDescription().ServiceType);

                var securitySetting = setting.WcfSecuritySetting;
                if (securitySetting.PasswordCheck.Enable)
                {
                    if (securitySetting.PasswordCheck.Direction == OperationDirection.Both || securitySetting.PasswordCheck.Direction == OperationDirection.Reply)
                    {
                        clientContext.Password = securitySetting.PasswordCheck.Password;
                    }
                }

                var logSetting = setting.WcfLogSetting;
                if (logSetting.Enabled && logSetting.MessageInfoSetting.Enabled)
                {
                    var direct = logSetting.MessageInfoSetting.MessageDirection;
                    if (direct == MessageDirection.Both ||
                        direct == MessageDirection.Send)
                    {
                        var log = WcfLogProvider.GetServerMessageInfo(
                            "ServerMessageInspector.BeforeSendReply",
                            MessageDirection.Send,
                            reply.ToString());
                        MongodbService.MongodbInsertService.Insert(log);
                    }
                }

            }
            catch (Exception ex)
            {
                ex.Handle(WcfLogProvider.ModuleName, "ServerMessageInspector", "BeforeSendReply");
            }
        }
Example #2
0
        public void BeforeSendReply(ref Message reply, object correlationState)
        {
            try
            {
                var clientContext = new ClientApplicationContext();
                clientContext.ServerMachineIP   = CommonConfiguration.MachineIP;
                clientContext.RequestIdentity   = ServerApplicationContext.Current.RequestIdentity;
                clientContext.ServerExceptionID = ServerApplicationContext.Current.ServerExceptionID ?? "";

                var serviceType = OperationContext.Current.GetCurrentServiceDescription().ServiceType;
                if (!serviceVersionCache.ContainsKey(serviceType.FullName))
                {
                    lock (locker)
                    {
                        if (!serviceVersionCache.ContainsKey(serviceType.FullName))
                        {
                            serviceVersionCache.Add(serviceType.FullName, serviceType.Assembly.GetName().Version.ToString());
                        }
                    }
                }
                clientContext.ServerVersion = serviceVersionCache[serviceType.FullName];

                reply.SetApplicationContext(clientContext);

                var setting = WcfSettingManager.CurrentServerSetting(OperationContext.Current.GetCurrentServiceDescription().ServiceType);

                var securitySetting = setting.WcfSecuritySetting;
                if (securitySetting.PasswordCheck.Enable)
                {
                    if (securitySetting.PasswordCheck.Direction == OperationDirection.Both || securitySetting.PasswordCheck.Direction == OperationDirection.Reply)
                    {
                        clientContext.Password = securitySetting.PasswordCheck.Password;
                    }
                }

                var logSetting = setting.WcfLogSetting;
                if (logSetting.Enabled && logSetting.MessageInfoSetting.Enabled)
                {
                    var direct = logSetting.MessageInfoSetting.MessageDirection;
                    if (direct == MessageDirection.Both ||
                        direct == MessageDirection.Send)
                    {
                        var log = WcfLogProvider.GetServerMessageInfo(
                            "ServerMessageInspector.BeforeSendReply",
                            MessageDirection.Send,
                            reply.ToString());
                        MongodbService.MongodbInsertService.Insert(log);
                    }
                }
            }
            catch (Exception ex)
            {
                ex.Handle(WcfLogProvider.ModuleName, "ServerMessageInspector", "BeforeSendReply");
            }
        }
Example #3
0
        public object BeforeSendRequest(ref Message request, IClientChannel channel)
        {
            try
            {
                var channelType = channel.GetType();

                var serverContext = new ServerApplicationContext();

                if (HttpContext.Current != null
                    && HttpContext.Current.Items != null
                    && HttpContext.Current.Items[AppInfoCenterConfiguration.Const.ContextIdentityKey] != null)
                {
                    serverContext.RequestIdentity = HttpContext.Current.Items[AppInfoCenterConfiguration.Const.ContextIdentityKey].ToString();
                }
                else if (CallContext.GetData(AppInfoCenterConfiguration.Const.ContextIdentityKey) != null)
                {
                    serverContext.RequestIdentity = CallContext.GetData(AppInfoCenterConfiguration.Const.ContextIdentityKey).ToString();
                }
                else
                {
                    serverContext.RequestIdentity = Guid.NewGuid().ToString();
                }

                var clientContext = new ClientApplicationContext();
                clientContext.RequestIdentity = serverContext.RequestIdentity;
                ClientApplicationContext.Current = clientContext;

                var setting = WcfSettingManager.CurrentClientSetting(channelType);
                var securitySetting = setting.WcfSecuritySetting;
                if (securitySetting.PasswordCheck.Enable)
                {
                    if (securitySetting.PasswordCheck.Direction == OperationDirection.Both || securitySetting.PasswordCheck.Direction == OperationDirection.Request)
                    {
                        serverContext.Password = securitySetting.PasswordCheck.Password;
                    }
                }

                var logSetting = setting.WcfLogSetting;
                if (logSetting.Enabled && logSetting.MessageInfoSetting.Enabled)
                {
                    var direct = logSetting.MessageInfoSetting.MessageDirection;
                    if (direct == MessageDirection.Both || direct == MessageDirection.Send)
                    {
                        var log = WcfLogProvider.GetClientMessageInfo(
                        channelType.FullName,
                        ClientApplicationContext.Current.RequestIdentity,
                        "ClientMessageInspector.BeforeSendRequest",
                        MessageDirection.Send,
                        request.ToString());
                        MongodbService.MongodbInsertService.Insert(log);
                    }
                }

                serverContext.ClientMachineIP = CommonConfiguration.MachineIP;

                if (!contractVersionCache.ContainsKey(channelType.FullName))
                {
                    lock (locker)
                    {
                        if (!contractVersionCache.ContainsKey(channelType.FullName))
                        {
                            contractVersionCache.Add(channelType.FullName, channelType.Assembly.GetName().Version.ToString());
                        }
                    }
                }
                serverContext.ClientVersion = contractVersionCache[channelType.FullName];
                request.SetApplicationContext(serverContext);

                return channelType;
            }
            catch (Exception ex)
            {
                ex.Handle(WcfLogProvider.ModuleName, "ClientMessageInspector" , "BeforeSendRequest");
            }
            return channel.GetType();
        }
Example #4
0
        public object BeforeSendRequest(ref Message request, IClientChannel channel)
        {
            try
            {
                var channelType = channel.GetType();

                var serverContext = new ServerApplicationContext();

                if (HttpContext.Current != null &&
                    HttpContext.Current.Items != null &&
                    HttpContext.Current.Items[AppInfoCenterConfiguration.Const.ContextIdentityKey] != null)
                {
                    serverContext.RequestIdentity = HttpContext.Current.Items[AppInfoCenterConfiguration.Const.ContextIdentityKey].ToString();
                }
                else if (CallContext.GetData(AppInfoCenterConfiguration.Const.ContextIdentityKey) != null)
                {
                    serverContext.RequestIdentity = CallContext.GetData(AppInfoCenterConfiguration.Const.ContextIdentityKey).ToString();
                }
                else
                {
                    serverContext.RequestIdentity = Guid.NewGuid().ToString();
                }

                var clientContext = new ClientApplicationContext();
                clientContext.RequestIdentity    = serverContext.RequestIdentity;
                ClientApplicationContext.Current = clientContext;

                var setting         = WcfSettingManager.CurrentClientSetting(channelType);
                var securitySetting = setting.WcfSecuritySetting;
                if (securitySetting.PasswordCheck.Enable)
                {
                    if (securitySetting.PasswordCheck.Direction == OperationDirection.Both || securitySetting.PasswordCheck.Direction == OperationDirection.Request)
                    {
                        serverContext.Password = securitySetting.PasswordCheck.Password;
                    }
                }

                var logSetting = setting.WcfLogSetting;
                if (logSetting.Enabled && logSetting.MessageInfoSetting.Enabled)
                {
                    var direct = logSetting.MessageInfoSetting.MessageDirection;
                    if (direct == MessageDirection.Both || direct == MessageDirection.Send)
                    {
                        var log = WcfLogProvider.GetClientMessageInfo(
                            channelType.FullName,
                            ClientApplicationContext.Current.RequestIdentity,
                            "ClientMessageInspector.BeforeSendRequest",
                            MessageDirection.Send,
                            request.ToString());
                        MongodbService.MongodbInsertService.Insert(log);
                    }
                }

                serverContext.ClientMachineIP = CommonConfiguration.MachineIP;

                if (!contractVersionCache.ContainsKey(channelType.FullName))
                {
                    lock (locker)
                    {
                        if (!contractVersionCache.ContainsKey(channelType.FullName))
                        {
                            contractVersionCache.Add(channelType.FullName, channelType.Assembly.GetName().Version.ToString());
                        }
                    }
                }
                serverContext.ClientVersion = contractVersionCache[channelType.FullName];
                request.SetApplicationContext(serverContext);

                return(channelType);
            }
            catch (Exception ex)
            {
                ex.Handle(WcfLogProvider.ModuleName, "ClientMessageInspector", "BeforeSendRequest");
            }
            return(channel.GetType());
        }