예제 #1
0
 protected void OnInvokeCanceled(ServiceProxyInvokeEventArgs args)
 {
     if (InvokeCanceled != null)
     {
         InvokeCanceled(this, args);
     }
 }
예제 #2
0
 protected void OnInvocationException(ServiceProxyInvokeEventArgs args)
 {
     if (InvocationException != null)
     {
         InvocationException(this, args);
     }
 }
예제 #3
0
 protected void OnInvokedMethod(ServiceProxyInvokeEventArgs args)
 {
     if (InvokedMethod != null)
     {
         InvokedMethod(this, args);
     }
 }
예제 #4
0
 /// <summary>
 /// Fires the Got event
 /// </summary>
 /// <param name="args"></param>
 protected void OnPosted(ServiceProxyInvokeEventArgs <T> args)
 {
     if (Posted != null)
     {
         Posted(this, args);
     }
 }
예제 #5
0
        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);
        }
예제 #6
0
        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);;
        }
예제 #7
0
 /// <summary>
 /// Fires the Getting event
 /// </summary>
 /// <param name="args"></param>
 protected void OnGetting(ServiceProxyInvokeEventArgs <T> args)
 {
     if (Getting != null)
     {
         Getting(this, args);
     }
 }
예제 #8
0
 /// <summary>
 /// Fires the Got event
 /// </summary>
 /// <param name="args"></param>
 protected void OnGot(ServiceProxyInvokeEventArgs <T> args)
 {
     if (Got != null)
     {
         Got(this, args);
     }
 }
예제 #9
0
        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);
        }
예제 #10
0
        /// <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);
        }
예제 #11
0
        /// <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));
        }
예제 #12
0
 protected void OnInvokeCanceled(ServiceProxyInvokeEventArgs args)
 {
     InvokeCanceled?.Invoke(this, args);
 }
예제 #13
0
 protected void OnInvokedMethod(ServiceProxyInvokeEventArgs args)
 {
     InvokedMethod?.Invoke(this, args);
 }
예제 #14
0
 protected void OnInvocationException(ServiceProxyInvokeEventArgs args)
 {
     InvocationException?.Invoke(this, args);
 }