Esempio n. 1
0
        public bool AddService(string serviceName, string hostName, int port)
        {
            if (string.IsNullOrWhiteSpace(serviceName) || string.IsNullOrWhiteSpace(hostName) || port <= 0)
            {
                return(false);
            }
            ClinentInfo tempClientInfo = new ClinentInfo(serviceName, hostName, port);

            UseServices.AddService(tempClientInfo);
            return(true);
        }
        /// <summary>
        /// 派发请求
        /// </summary>
        /// <param name="useApi"></param>
        /// <param name="useClient"></param>
        /// <param name="ifContinueQueryString"></param>
        /// <returns></returns>
        private object TransforRequest(string useApi, ClinentInfo useClient, bool ifContinueQueryString = true)
        {
            //请求跳转
            StringBuilder usePath = new StringBuilder();

            usePath.Append(useClient.UseHostName + ":" + useClient.UsePort + "/" + useApi);

            var useQueryStrings = HttpContext.Current.Request.QueryString;

            bool tag = true;

            foreach (var oneKey in useQueryStrings.AllKeys)
            {
                //查询字符串跳过判断
                if (ifContinueQueryString && (oneKey == m_strServiceName || m_strServiceName == m_strUseApi))
                {
                    continue;
                }

                //附加参数
                if (tag)
                {
                    tag = false;
                    usePath.Append("?");
                }

                usePath.Append(oneKey + "=" + useQueryStrings[oneKey] + "&");
            }

            //使用的跳转地址
            var tempPath = usePath.ToString().TrimEnd('&');

            //发起远程代理
            HttpClient tempUseClient = new HttpClient();

            var tempResult = tempUseClient.GetAsync(tempPath).Result;

            return(tempResult);
        }