Ejemplo n.º 1
0
        /// <summary>
        /// 获取客户端信息,备用记录日志
        /// </summary>
        public CommonWcfBll()
        {
            #region
            OperationContext context = OperationContext.Current;
            if (context != null)
            {
                //获取客户端请求的路径
                string AbsolutePath = context.EndpointDispatcher.EndpointAddress.Uri.AbsolutePath;
                if (!AbsolutePath.Contains("Com/FrameWork/Helper/Wcf"))
                {
                    //获取客户端ip和端口
                    MessageProperties             properties = context.IncomingMessageProperties;
                    RemoteEndpointMessageProperty endpoint   = properties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
                    string client_ip = endpoint.Address;
                    //int client_port = endpoint.Port;

                    //获取客户端请求的契约信息
                    //string contract_name = context.EndpointDispatcher.ContractName;
                    //获取客户端请求的路径
                    //Uri request_uri = context.EndpointDispatcher.EndpointAddress.Uri;
                    string sessionid  = context.SessionId;
                    string wcfappname = HeaderOperater.GetServiceWcfAppNameHeader(context);
                    wcfappname              = wcfappname == null ? "" : wcfappname;
                    context.Channel.Closed += (object sender, EventArgs e) =>
                    {
                        //Console.WriteLine(sessionid + "请求结束:" + client_ip + ":" + client_port + "->" + request_uri.AbsolutePath);
                        MonitorData.Instance.UpdateUrlConnNums(client_ip + "_" + wcfappname, AbsolutePath, false);
                    };

                    //Console.WriteLine(sessionid + "请求开始:" + client_ip + ":" + client_port + "->" + request_uri.AbsolutePath);
                    Hashtable ht = new Hashtable();
                    ht.Add("ip", client_ip + "_" + wcfappname);
                    ht.Add("url", AbsolutePath);
                    ht.Add("isadd", true);
                    Thread th = new Thread(new ParameterizedThreadStart(Run));
                    th.Start(ht);
                }
            }
            #endregion
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 调用方法前 输出参数值
        /// </summary>
        /// <param name="operationName"></param>
        /// <param name="inputs"></param>
        /// <returns></returns>
        public object BeforeCall(string operationName, object[] inputs)
        {
            String guid = Guid.NewGuid().ToString();

            try
            {
                if (WcfBeforeCallEvent != null)
                {
                    OperationContext context      = OperationContext.Current;
                    string           AbsolutePath = "";
                    if (context != null)
                    {
                        //获取传递的自定义消息头
                        HeaderContext headercontext = HeaderOperater.GetServiceWcfHeader(context);
                        string        wcfappname    = HeaderOperater.GetServiceWcfAppNameHeader(context);
                        wcfappname = wcfappname == null ? "" : wcfappname;
                        if (headercontext != null)
                        {
                            guid = headercontext.CorrelationState;
                        }

                        //获取客户端请求的路径
                        AbsolutePath = context.EndpointDispatcher.EndpointAddress.Uri.AbsolutePath;

                        //获取客户端ip和端口
                        MessageProperties             properties = context.IncomingMessageProperties;
                        RemoteEndpointMessageProperty endpoint   = properties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
                        string client_ip = endpoint.Address;
                        //int client_port = endpoint.Port;

                        if (!AbsolutePath.Contains("Com/FrameWork/Helper/Wcf"))
                        {
                            Hashtable ht = new Hashtable();
                            ht.Add("ip", client_ip + "_" + wcfappname);
                            ht.Add("url", AbsolutePath);
                            ht.Add("operatename", operationName);
                            //MonitorData.Instance.UpdateOperateNums(client_ip, AbsolutePath, operationName);
                            Thread th = new Thread(new ParameterizedThreadStart(Run));
                            th.Start(ht);
                        }
                    }
                    WcfBeforeCallEvent(operationName, inputs, AbsolutePath, guid);

                    #region
                    //Console.WriteLine("返回操作开始:" + AbsolutePath + "/" + operationName);
                    //Console.WriteLine("*************调用操作编号:" + guid.ToString() + "**************");
                    //for (int i = 0; i < inputs.Length; i++)
                    //{

                    //    Type T = inputs[i].GetType();
                    //    Console.WriteLine("操作参数" + i.ToString() + "  类型为:" + T.ToString());
                    //    Console.WriteLine("操作参数" + i.ToString() + "  ToString为:" + inputs[i].ToString());
                    //    Console.WriteLine("操作参数" + i.ToString() + "  属性:");
                    //    PropertyInfo[] PIs = T.GetProperties();
                    //    foreach (PropertyInfo PI in PIs)
                    //    {
                    //        Console.Write(PI.Name + ":");
                    //        Console.WriteLine(PI.GetValue(inputs[i], null));
                    //    }

                    //}
                    #endregion
                }
            }
            catch { }

            return(guid);
        }