protected void OnInvokeCanceled(ServiceProxyInvokeEventArgs args) { if (InvokeCanceled != null) { InvokeCanceled(this, args); } }
protected void OnInvocationException(ServiceProxyInvokeEventArgs args) { if (InvocationException != null) { InvocationException(this, args); } }
protected void OnInvokedMethod(ServiceProxyInvokeEventArgs args) { if (InvokedMethod != null) { InvokedMethod(this, args); } }
/// <summary> /// Fires the Got event /// </summary> /// <param name="args"></param> protected void OnPosted(ServiceProxyInvokeEventArgs <T> args) { if (Posted != null) { Posted(this, args); } }
protected virtual string Post(ServiceProxyInvokeEventArgs invokeArgs, HttpWebRequest request) { ServiceProxyInvokeEventArgs <T> args = invokeArgs.CopyAs <ServiceProxyInvokeEventArgs <T> >(); args.Client = this; args.GenericClient = this; OnPosting(args); string result = string.Empty; if (args.CancelInvoke) { OnPostCanceled(args); } else { string jsonParamsString = ApiParameters.ParametersToJsonParamsObjectString(args.PostParameters); request.ContentType = "application/json; charset=utf-8"; WriteJsonParams(jsonParamsString, request); result = GetServiceProxyResponseString(request); args.Request = request; OnPosted(args); } return(result); }
protected virtual string Get(ServiceProxyInvokeEventArgs argsIn) { ServiceProxyInvokeEventArgs <T> args = argsIn.CopyAs <ServiceProxyInvokeEventArgs <T> >(); args.Client = this; args.GenericClient = this; string className = args.ClassName; string methodName = args.MethodName; string queryStringParameters = args.QueryStringParameters; OnGetting(args); string result = string.Empty; if (args.CancelInvoke) { OnGetCanceled(args); } else { HttpWebRequest request = GetServiceProxyRequest(ServiceProxyVerbs.GET, className, methodName, queryStringParameters); result = GetServiceProxyResponseString(request); args.Request = request; OnGot(args); } return(result);; }
/// <summary> /// Fires the Getting event /// </summary> /// <param name="args"></param> protected void OnGetting(ServiceProxyInvokeEventArgs <T> args) { if (Getting != null) { Getting(this, args); } }
/// <summary> /// Fires the Got event /// </summary> /// <param name="args"></param> protected void OnGot(ServiceProxyInvokeEventArgs <T> args) { if (Got != null) { Got(this, args); } }
protected internal virtual string DoInvoke(ServiceProxyInvokeEventArgs args) { string baseAddress = args.BaseAddress; string className = args.ClassName; string methodName = args.MethodName; object[] parameters = args.PostParameters; try { string tmp = string.Empty; GetQueryStringAndVerb(methodName, parameters, out string queryStringParameters, out ServiceProxyVerbs verb); if (verb == ServiceProxyVerbs.POST) { tmp = Post(args); } else { args.QueryStringParameters = queryStringParameters; tmp = Get(args); } return(tmp); } catch (Exception ex) { args.Exception = ex; OnInvocationException(args); } return(string.Empty); }
/// <summary> /// This method provides core method invoke functionality. /// </summary> /// <param name="baseAddress"></param> /// <param name="className"></param> /// <param name="methodName"></param> /// <param name="parameters"></param> /// <returns></returns> public string Invoke(string baseAddress, string className, string methodName, params object[] parameters) { if (!Methods.Contains(methodName) && typeof(T).Name.Equals(className)) { throw Args.Exception <InvalidOperationException>("{0} is not proxied from type {1}", methodName, className); } if (!baseAddress.EndsWith("/")) { baseAddress = string.Format("{0}", baseAddress); } ServiceProxyInvokeEventArgs args = new ServiceProxyInvokeEventArgs { BaseAddress = baseAddress, ClassName = className, Client = this, MethodName = methodName, PostParameters = parameters }; OnInvokingMethod(args); string result = string.Empty; if (args.CancelInvoke) { OnInvokeCanceled(args); } else { string tmp = DoInvoke(args); result = tmp; LastResponse = result; OnInvokedMethod(args); } return(result); }
/// <summary> /// Post to the url representing the specified method call. Content type used /// will be "application/json; charset=utf-8";. This can be overridden in a derived /// class by overriding WriteJsonParams or GetServiceProxyResponse, each of which /// is called after the ContentType is set on the request. /// </summary> /// <param name="args"></param> /// <returns></returns> public virtual string Post(ServiceProxyInvokeEventArgs args) { HttpWebRequest request = GetServiceProxyRequest(ServiceProxyVerbs.POST, args.ClassName, args.MethodName, "nocache=".RandomLetters(4)); return(Post(args, request)); }
protected void OnInvokeCanceled(ServiceProxyInvokeEventArgs args) { InvokeCanceled?.Invoke(this, args); }
protected void OnInvokedMethod(ServiceProxyInvokeEventArgs args) { InvokedMethod?.Invoke(this, args); }
protected void OnInvocationException(ServiceProxyInvokeEventArgs args) { InvocationException?.Invoke(this, args); }