예제 #1
0
        /// <summary>
        /// 执行函数
        /// </summary>
        private APIResault DoMethods(HttpListenerRequest request)
        {
            ServiceRequest req = new ServiceRequest();

            req.Load(request);
            string arg    = req.GetArgString();
            string method = req.MethodName;
            string url    = request.Url.AbsolutePath;

            if (string.IsNullOrWhiteSpace(method))
            {
                return(ApiCommon.GetFault("函数MethodName不能为空"));
            }
            try
            {
                APIResault con = RunMethod(url, method, arg, request);
                if (_message != null && _message.ShowLog)
                {
                    string mess = con.Message;

                    _message.Log(mess);
                }
                return(con);
            }
            catch (Exception ex)
            {
                if (OnException != null)
                {
                    OnException(ex);
                }
                return(ApiCommon.GetException(ex));
            }
        }
예제 #2
0
        /// <summary>
        /// 执行函数
        /// </summary>
        private APIResault DoMethods(HttpListenerRequest request)
        {
            ServiceRequest req = new ServiceRequest();

            req.Load(request);
            string arg    = req.GetArgString();
            string method = req.MethodName;
            string url    = request.Url.AbsolutePath;
            string ip     = LanUnit.GetHostAddress(request);


            if (_lanUnit != null && _lanUnit.IsAllowIP(ip))
            {
                return(ApiCommon.GetException(new System.Net.WebException("调用IP:" + ip + "不在白名单内")));
            }

            if (string.IsNullOrWhiteSpace(method))
            {
                return(ApiCommon.GetFault("函数MethodName不能为空"));
            }
            try
            {
                APIResault con = RunMethod(url, method, arg, request);
                if (_message != null && _message.ShowLog)
                {
                    string mess = con.Message;

                    _message.Log(mess);
                }
                return(con);
            }
            catch (Exception ex)
            {
                if (OnException != null)
                {
                    OnException(ex);
                }
                return(ApiCommon.GetException(ex));
            }
        }