예제 #1
0
        /// <summary>
        /// Executes before sending a request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="channel">The channel.</param>
        public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel)
        {
            var service = channel.GetType().Name;
            var method  = !string.IsNullOrEmpty(request.Headers.Action) && request.Headers.Action.Contains('/') ? request.Headers.Action.Split('/').Last() : request.Headers.Action;

            // Start the profiler step just before sending the request
            return(MiniProfiler.Current.Step(string.Format("WCF: {0}.{1}", service, method)));
        }
예제 #2
0
        private static void ExtractNames(Message message, IClientChannel channel, out string webServiceName, out string operationName)
        {
            webServiceName = channel.GetType().Name;
            operationName  = message.Headers.Action;
            Uri tempUri;

            if (Uri.TryCreate(operationName, UriKind.Absolute, out tempUri))
            {
                var components = tempUri.GetComponents(UriComponents.Path, UriFormat.Unescaped).Split('/');
                if (components.Length > 0)
                {
                    operationName = components.Last();
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Will retrieve SYNC FLAG based upon the value of the IsOneWay
        /// attribute for the operation being invoked.
        /// </summary>
        /// <param name="channel"></param>
        /// <param name="opName"></param>
        /// <returns></returns>
        public static bool GetSyncFlag(IClientChannel channel, string opName)
        {
            bool bSync = true;

            if (channel != null)
            {
                Type t = Type.GetType(channel.GetType().AssemblyQualifiedName);
                if (t != null)
                {
                    OperationDescription opDesc = GetOperationDescription(t, opName);
                    if (opDesc != null && opDesc.IsOneWay == true)
                    {
                        bSync = false;
                    }
                }
            }

            return(bSync);
        }
예제 #4
0
        public HttpClientChannel(IClientChannel channel, InstanceLogger logger, HttpServerChannel serverChannel = null)
        {
            var sharedLockChannel = serverChannel != null?serverChannel.GetInnerChannel() : null;

            if (channel.GetType() != typeof(LockableClientChannel))
            {
                channel = new LockableClientChannel(channel, sharedLockChannel);
            }
            this.channel = (LockableClientChannel)channel;
            this.id      = channel.ID;
            this.name    = channel.Name;
            handlers     = new IChannelExtensions.ChannelHandlers
            {
                ChannelClosed    = channelClosedHandler,
                ChannelReady     = channelReadyHandler,
                ResponseReceived = responseReceivedHandler,
                RequestSent      = requestSentHandler,
                ErrorOccured     = errorOccuredHandler,
            };
            channel.BindAllEvents(handlers);
            parser      = new HttpMessageParser(logger, true);
            this.logger = logger;
        }
예제 #5
0
        public object BeforeSendRequest(ref Message request, IClientChannel channel)
        {
#if DEBUG
            var message = request.ToString();
            Console.WriteLine("Client send message:" + message);
#endif
            try
            {
                var channelType = channel.GetType();

                var serverContext = new ServerApplicationContext();
                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());
                        WcfServiceLocator.GetLogService().LogWithoutException(log);
                    }
                }

                serverContext.RequestIdentity   = Guid.NewGuid().ToString();
                serverContext.ClientMachineName = WcfLogProvider.MachineName;

                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)
            {
                LocalLogService.Log(ex.ToString());
            }
            return(channel.GetType());
        }
예제 #6
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();
        }
예제 #7
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());
        }
예제 #8
0
        public object BeforeSendRequest(ref Message request, IClientChannel channel)
        {
            #if DEBUG
            var message = request.ToString();
            Console.WriteLine("Client send message:" + message);
            #endif
            try
            {
                var channelType = channel.GetType();

                var serverContext = new ServerApplicationContext();
                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());
                        WcfServiceLocator.GetLogService().LogWithoutException(log);
                    }
                }

                serverContext.RequestIdentity = Guid.NewGuid().ToString();
                serverContext.ClientMachineName = WcfLogProvider.MachineName;

                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)
            {
                LocalLogService.Log(ex.ToString());
            }
            return channel.GetType();
        }