コード例 #1
0
        private string AuthorizeMethod(string name, WebHeaderCollection header, out ServiceItem service)
        {
            service = null;
            var response = WebOperationContext.Current.OutgoingResponse;

            //检测服务名称
            if (name == "favicon.ico")
            {
                response.StatusCode = HttpStatusCode.NotFound;
                var item = new HttpProxyResult {
                    Code = (int)response.StatusCode, Message = "Service 【" + name + "】 not found."
                };
                return(SerializeJson(item));
            }
            else if (!services.Any(p => string.Compare(p.Name, name, true) == 0))
            {
                response.StatusCode = HttpStatusCode.NotFound;
                var item = new HttpProxyResult {
                    Code = (int)response.StatusCode, Message = "Method 【" + name + "】 not found."
                };
                return(SerializeJson(item));
            }
            else
            {
                #region 进行认证处理

                service = services.Single(p => string.Compare(p.Name, name, true) == 0);

                //认证处理
                if (service.Authorized)
                {
                    var result = AuthorizeHeader(header);
                    if (result.Code == (int)HttpStatusCode.OK)
                    {
                        return(null);
                    }
                    else
                    {
                        return(SerializeJson(result));
                    }
                }

                #endregion
            }

            return(null);
        }
コード例 #2
0
        private string AuthorizeMethod(string name, WebHeaderCollection header, out ServiceItem service)
        {
            service = null;
            var response = WebOperationContext.Current.OutgoingResponse;

            //检测服务名称
            if (name == "favicon.ico")
            {
                response.StatusCode = HttpStatusCode.NotFound;
                var item = new HttpProxyResult { Code = (int)response.StatusCode, Message = "Service 【" + name + "】 not found." };
                return SerializeJson(item);
            }
            else if (!services.Any(p => string.Compare(p.Name, name, true) == 0))
            {
                response.StatusCode = HttpStatusCode.NotFound;
                var item = new HttpProxyResult { Code = (int)response.StatusCode, Message = "Method 【" + name + "】 not found." };
                return SerializeJson(item);
            }
            else
            {
                #region 进行认证处理

                service = services.Single(p => string.Compare(p.Name, name, true) == 0);

                //认证处理
                if (service.Authorized)
                {
                    var result = AuthorizeHeader(header);
                    if (result.Code == (int)HttpStatusCode.OK)
                        return null;
                    else
                        return SerializeJson(result);
                }

                #endregion
            }

            return null;
        }