/// <summary> /// 方法调用 /// </summary> /// <param name="kind"></param> /// <param name="method"></param> /// <param name="parameters"></param> /// <returns></returns> public object Invoke(string kind, string method, NameValueCollection parameters, out Type retType) { WebOperationContext context = WebOperationContext.Current; BusinessMethodModel metadata = pool.FindMethod(kind, method); //返回类型 retType = metadata.Method.ReturnType; //处理请求类型 if (metadata.HttpMethod == HttpMethod.POST && context.IncomingRequest.Method.ToUpper() == "GET") { throw new RESTfulException((int)HttpStatusCode.MethodNotAllowed, "Resources can only by the [" + metadata.HttpMethod + "] way to acquire."); } //实例对象 object instance = null; try { //调用方法 object[] arguments = ParameterHelper.Convert(metadata.Parameters, parameters); instance = register.Resolve(metadata.Service); return(DynamicCalls.GetMethodInvoker(metadata.Method)(instance, arguments)); } finally { register.Release(instance); } }
private string CallApi(string method, Dictionary <string, Object> parameters) { using (WebClient wc = new WebClient()) { wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; wc.Credentials = new NetworkCredential(GatewayConstants.username, GatewayConstants.password); string parameterStr = ParameterHelper.Convert(parameters); return(wc.UploadString(GatewayConstants.gatewayUrl + method, parameterStr)); } }
public void EmptyDictionaryReturnsEmptyString() { string paramString = _helper.Convert(_parameters); Assert.AreEqual("", paramString); }