Ejemplo n.º 1
0
        /// <summary>
        /// 异步方法
        /// </summary>
        /// <param name="SPname">存储过程名称</param>
        /// <param name="LD">参数集合</param>
        /// <param name="RouteName">路由名称</param>
        /// <returns></returns>
        public async Task <BllClass> CallWebAPI_Async(string SPname, List <DbParameter> LD, string RouteName)
        {
            List <IoRyDbParameter> li = new List <IoRyDbParameter>();

            foreach (var item in LD)
            {
                IoRyDbParameter ip = new IoRyDbParameter();
                ip.Name  = item.ParameterName;
                ip.Value = Convert.ToString(item.Value);
                li.Add(ip);
            }
            BllClass bc = new BllClass();

            bc.RouteName = RouteName;
            DLLjson dj = new DLLjson();

            dj.SQL_string = SPname;
            dj.ConfigPath = this.ConfigPth;
            dj.DbParaList = li;
            bc.JsonIn     = JsonConvert.SerializeObject(dj);
            string rts = await CallWebAPI_Async(bc);

            BllClass bcrt = JsonConvert.DeserializeObject <BllClass>(rts);

            if (!bcrt.IsNormal)
            {
                throw new Exception(bcrt.ErrorMsg);
            }
            return(bcrt);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 同步基础方法
 /// </summary>
 /// <param name="bcin"></param>
 /// <returns></returns>
 string CallWebAPI_Syn(BllClass bcin)
 {
     using (var client = new HttpClient())
     {
         HttpContent content = new StringContent(JsonConvert.SerializeObject(bcin));
         content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
         HttpResponseMessage response = client.PostAsync(this.Url, content).Result;
         response.EnsureSuccessStatusCode();//用来抛异常的
         string responseBody = response.Content.ReadAsStringAsync().Result;
         return(responseBody);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 同步调用方法
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <param name="RouteName">路由名称</param>
        /// <returns></returns>
        public BllClass CallWebAPI_Syn(string sql, string RouteName)
        {
            BllClass bc = new BllClass();

            bc.RouteName = RouteName;
            DLLjson dj = new DLLjson();

            dj.SQL_string = sql;
            dj.ConfigPath = this.ConfigPth;
            bc.JsonIn     = JsonConvert.SerializeObject(dj);
            string   rts  = CallWebAPI_Syn(bc);
            BllClass bcrt = JsonConvert.DeserializeObject <BllClass>(rts);

            if (!bcrt.IsNormal)
            {
                throw new Exception(bcrt.ErrorMsg);
            }
            return(bcrt);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 异步方法
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <param name="cuser">操作者</param>
        /// <param name="RouteName">路由名称</param>
        /// <returns></returns>
        public async Task <BllClass> CallWebAPI_Async(string sql, string cuser, string RouteName)
        {
            BllClass bc = new BllClass();

            bc.RouteName = RouteName;
            DLLjson dj = new DLLjson();

            dj.SQL_string = sql;
            dj.ConfigPath = this.ConfigPth;
            dj.Operater   = cuser;
            bc.JsonIn     = JsonConvert.SerializeObject(dj);
            string rts = await CallWebAPI_Async(bc);

            BllClass bcrt = JsonConvert.DeserializeObject <BllClass>(rts);

            if (!bcrt.IsNormal)
            {
                throw new Exception(bcrt.ErrorMsg);
            }
            return(bcrt);
        }