public static string Invoke(ApiRequestData requestData, bool isPost) { try { string method = ""; if (requestData.RequestString.TryGetValue(Constants.METHOD, out method)) { var provider = ProviderFactory.Create(method, isPost); if (provider == null) { return(ApiResult.CreateErrorResult(requestData.RequestId, Common.ResponseCode.ResponseType.Miss_Method, method)); } return(provider.Invoke(requestData)); } else { return(ApiResult.CreateErrorResult(requestData.RequestId, Common.ResponseCode.ResponseType.Required, Constants.METHOD)); } } catch (Exception ex) { return(ApiResult.CreateErrorResult(requestData.RequestId, ResponseType.Error, ex.Message)); } }
public override string Invoke(ApiRequestData requestData) { var method = requestData.RequestString[Constants.METHOD]; if (this.apimethod.Name.EqualsIgnoreCase(method)) { var apiType = this.apimethod.Type; var invokeMethod = apiType.GetMethod("InvokeRequest"); return(invokeMethod.Invoke(Activator.CreateInstance(apiType), new[] { requestData }).ToString()); } else { return(ApiResult.CreateErrorResult(requestData.RequestId, ResponseType.Miss_Method, method)); } }
public override string Invoke(ApiRequestData requestData) { WebUtils web = new WebUtils(); var url = apimethod.Urls[0]; url += ConvertToWebUrl(requestData.RequestString[Constants.METHOD]); IDictionary <string, string> dictionary = requestData.RequestString; dictionary.Add(Constants.INVOKETYPE, ((int)this.apimethod.InvokeType).ToString()); dictionary.Add(Constants.REQUESTID, requestData.RequestId.ToString()); try { if (IsPost) { url = WebUtils.BuildRequestUrl(url, requestData.GetRequestString); return(web.DoPost(url, dictionary)); } else { return(web.DoGet(url, dictionary)); } } catch (WebException we) { HttpWebResponse errorResponse = we.Response as HttpWebResponse; if (errorResponse.StatusCode == HttpStatusCode.NotFound) { return(ApiResult.CreateErrorResult(requestData.RequestId, ResponseType.Miss_Method, requestData.RequestString[Constants.METHOD])); } else { return(ApiResult.CreateErrorResult(requestData.RequestId, ResponseType.RouterError, ((int)errorResponse.StatusCode) + " " + requestData.RequestString[Constants.METHOD])); } } catch (Exception ex) { return(ApiResult.CreateErrorResult(requestData.RequestId, ResponseType.Error, ex.Message)); } }