Esempio n. 1
0
        //------------------------------------------
        // WCF METHODS WHICH RETURN A VALUE
        //------------------------------------------

        public static Task <RETURN_TYPE> CallWebMethodAsync <RETURN_TYPE, INTERFACE_TYPE>(
            string endpointAddress,
            string webMethodName,
            IDictionary <string, object> requestParameters,
            string soapVersion) where INTERFACE_TYPE : class
        {
            // Call the web method
            var webMethodsCaller = new CSHTML5_ClientBase <INTERFACE_TYPE> .WebMethodsCaller(endpointAddress);

            Task <RETURN_TYPE> task;

            try
            {
                task = webMethodsCaller.CallWebMethodAsync <RETURN_TYPE>(
                    webMethodName,
                    typeof(INTERFACE_TYPE),
                    typeof(RETURN_TYPE),
                    requestParameters,
                    soapVersion);
            }
            catch (MissingMethodException)
            {
                task = webMethodsCaller.CallWebMethodAsyncBeginEnd <RETURN_TYPE>(
                    webMethodName,
                    typeof(INTERFACE_TYPE),
                    typeof(RETURN_TYPE),
                    requestParameters,
                    soapVersion);
            }

            return(task);
        }
Esempio n. 2
0
        public static RETURN_TYPE EndCallWebMethod <RETURN_TYPE, INTERFACE_TYPE>(CSHTML5_ClientBase <INTERFACE_TYPE> clientBase, string methodName, Dictionary <string, Tuple <Type, object> > requestParameters) where INTERFACE_TYPE : class
        {
#if !FOR_DESIGN_TIME
            // Remove the word "End" from the method name (this is because the method called on the server's side is the one without "End")
            if (methodName.StartsWith("End")) //should always be the case
            {
                methodName = methodName.Substring(3);
            }

            // Read the XML result from the parameters:
            System.IAsyncResult  asyncResult          = (System.IAsyncResult)requestParameters["result"].Item2;
            WebMethodAsyncResult webMethodAsyncResult = (WebMethodAsyncResult)asyncResult;
            string xmlReturnedFromTheServer           = webMethodAsyncResult.XmlReturnedFromTheServer;

            // Call "EndCallWebMethod" to deserialize the result:
            var webMethodsCaller = new CSHTML5_ClientBase <INTERFACE_TYPE> .WebMethodsCaller(clientBase.INTERNAL_RemoteAddressAsString);

            RETURN_TYPE result = webMethodsCaller.EndCallWebMethod <RETURN_TYPE>(methodName, typeof(INTERFACE_TYPE), xmlReturnedFromTheServer);

            // Return the deserialized result:
            return(result);
#else
            return(default(RETURN_TYPE));
#endif
        }
Esempio n. 3
0
        public static object EndCallWebMethod <INTERFACE_TYPE>(
            string endpointAddress,
            string webMethodName,
            Type methodReturnType,
            IDictionary <string, object> requestParameters,
            string soapVersion) where INTERFACE_TYPE : class
        {
            // Read the XML result from the parameters
            IAsyncResult         asyncResult          = (IAsyncResult)requestParameters["result"];
            WebMethodAsyncResult webMethodAsyncResult = (WebMethodAsyncResult)asyncResult;
            string xmlReturnedFromTheServer           = webMethodAsyncResult.XmlReturnedFromTheServer;

            // Call "EndCallWebMethod" to deserialize the result
            var webMethodsCaller = new CSHTML5_ClientBase <INTERFACE_TYPE> .WebMethodsCaller(endpointAddress);

            object result = webMethodsCaller.EndCallWebMethod(
                webMethodName,
                typeof(INTERFACE_TYPE),
                methodReturnType,
                xmlReturnedFromTheServer,
                soapVersion);

            // Return the deserialized result
            return(result);
        }
Esempio n. 4
0
        public static RETURN_TYPE CallWebMethod <RETURN_TYPE, INTERFACE_TYPE>(CSHTML5_ClientBase <INTERFACE_TYPE> clientBase, string methodName, Dictionary <string, Tuple <Type, object> > requestParameters) where INTERFACE_TYPE : class
        {
#if !FOR_DESIGN_TIME
            var webMethodsCaller = new CSHTML5_ClientBase <INTERFACE_TYPE> .WebMethodsCaller(clientBase.INTERNAL_RemoteAddressAsString);

            return((RETURN_TYPE)webMethodsCaller.CallWebMethod(methodName, typeof(INTERFACE_TYPE), typeof(RETURN_TYPE), requestParameters));
#else
            return(default(RETURN_TYPE));
#endif
        }
Esempio n. 5
0
        public static RETURN_TYPE CallWebMethod <RETURN_TYPE, INTERFACE_TYPE>(string endpointAddress, string methodName, Dictionary <string, Tuple <Type, object> > requestParameters, string soapVersion) where INTERFACE_TYPE : class
        {
#if !FOR_DESIGN_TIME
            var webMethodsCaller = new CSHTML5_ClientBase <INTERFACE_TYPE> .WebMethodsCaller(endpointAddress);

            return((RETURN_TYPE)webMethodsCaller.CallWebMethod(methodName, typeof(INTERFACE_TYPE), typeof(RETURN_TYPE), requestParameters, soapVersion));
#else
            return(default(RETURN_TYPE));
#endif
        }
Esempio n. 6
0
        public static IAsyncResult BeginCallWebMethod <INTERFACE_TYPE>(
            string endpointAddress,
            string webMethodName,
            Type methodReturnType,
            IDictionary <string, object> requestParameters,
            string soapVersion) where INTERFACE_TYPE : class
        {
            // Read the parameters
            AsyncCallback callback   = (AsyncCallback)requestParameters["callback"];
            object        asyncState = requestParameters["asyncState"];

            // Note on the commentary below: we changed the Dictionary but it is still relevant.
            // Remove the "callback" and "asyncState" items from the "requestParameters" dictionary
            // so as to leave only the real parameters of the web method. For example, in case of
            // the web method "string GetData(int value1, int value2)", the "requestParameters" is
            // equal to:
            // new Dictionary<string, object>()
            // {
            //     {"value1", value1},
            //     {"value2", value2},
            //     {"callback", callback},
            //     {"asyncState", asyncState}
            // }
            // We need to remove the "callback" and "asyncState" because otherwise
            // they risk being serialized with the request.
            requestParameters.Remove("callback");
            requestParameters.Remove("asyncState");

            // Call the server
            var webMethodsCaller = new CSHTML5_ClientBase <INTERFACE_TYPE> .WebMethodsCaller(endpointAddress);

            var webMethodAsyncResult = new WebMethodAsyncResult(callback, asyncState);

            webMethodsCaller.BeginCallWebMethod(
                webMethodName,
                typeof(INTERFACE_TYPE),
                methodReturnType,
                requestParameters,
                (xmlReturnedFromTheServer) =>
            {
                // After server call has finished (not deserialized yet)
                webMethodAsyncResult.XmlReturnedFromTheServer = xmlReturnedFromTheServer;

                // This causes a call to "EndCallWebMethod" which will deserialize the response.
                webMethodAsyncResult.Completed();
            },
                soapVersion);

            return(webMethodAsyncResult);
        }
Esempio n. 7
0
        public static RETURN_TYPE CallWebMethod <RETURN_TYPE, INTERFACE_TYPE>(
            string endpointAddress,
            string webMethodName,
            IDictionary <string, object> requestParameters,
            string soapVersion) where INTERFACE_TYPE : class
        {
            var webMethodsCaller = new CSHTML5_ClientBase <INTERFACE_TYPE> .WebMethodsCaller(endpointAddress);

            return((RETURN_TYPE)webMethodsCaller.CallWebMethod(
                       webMethodName,
                       typeof(INTERFACE_TYPE),
                       typeof(RETURN_TYPE),
                       requestParameters,
                       soapVersion));
        }
Esempio n. 8
0
        //------------------------------------------
        // WCF METHODS WHICH RETURN A VALUE
        //------------------------------------------

        public static Task <RETURN_TYPE> CallWebMethodAsync <RETURN_TYPE, INTERFACE_TYPE>(CSHTML5_ClientBase <INTERFACE_TYPE> clientBase, string methodName, Dictionary <string, Tuple <Type, object> > requestParameters) where INTERFACE_TYPE : class
        {
#if !FOR_DESIGN_TIME
            // Remove the word "Async" from the method name (this is because the method called on the server's side is the one without "Async" at the end)
            if (methodName.EndsWith("Async")) //should always be the case
            {
                methodName = methodName.Remove(methodName.Length - 5);
            }

            // Call the web method:
            var webMethodsCaller = new CSHTML5_ClientBase <INTERFACE_TYPE> .WebMethodsCaller(clientBase.INTERNAL_RemoteAddressAsString);

            return(webMethodsCaller.CallWebMethodAsync <RETURN_TYPE>(methodName, typeof(INTERFACE_TYPE), typeof(RETURN_TYPE), requestParameters));
#else
            return(null);
#endif
        }
Esempio n. 9
0
        public static (RETURN_TYPE, Channels.MessageHeaders) CallWebMethod <RETURN_TYPE, INTERFACE_TYPE>(
            string endpointAddress,
            string webMethodName,
            IEnumerable <Channels.MessageHeader> outgoingMessageHeaders,
            IDictionary <string, object> requestParameters,
            string soapVersion) where INTERFACE_TYPE : class
        {
            var webMethodsCaller = new CSHTML5_ClientBase <INTERFACE_TYPE> .WebMethodsCaller(endpointAddress);

            var(typedResponseBody, incommingMessageHeaders) = webMethodsCaller.CallWebMethod(
                webMethodName,
                typeof(INTERFACE_TYPE),
                typeof(RETURN_TYPE),
                outgoingMessageHeaders,
                requestParameters,
                soapVersion);

            return((RETURN_TYPE)typedResponseBody, incommingMessageHeaders);
        }
Esempio n. 10
0
        public static System.IAsyncResult BeginCallWebMethod <RETURN_TYPE, INTERFACE_TYPE>(CSHTML5_ClientBase <INTERFACE_TYPE> clientBase, string methodName, Dictionary <string, Tuple <Type, object> > requestParameters) where INTERFACE_TYPE : class
        {
#if !FOR_DESIGN_TIME
            // Read the parameters:
            System.AsyncCallback callback = (System.AsyncCallback)requestParameters["callback"].Item2;
            object asyncState             = requestParameters["asyncState"].Item2;

            //Note on the commentary below: we changed the Dictionary but it is still relevant.
            // Remove the "callback" and "asyncState" items from the "requestParameters" dictionary so as to leave only the real parameters of the web method. For example, in case of the web method "string GetData(int value1, int value2)", the "requestParameters" is equal to: new Dictionary<string, object>() {{"value1", value1} , {"value2", value2} , {"callback", callback} , {"asyncState", asyncState} }). We need to remove the "callback" and "asyncState" because otherwise they risk being serialized with the request.
            requestParameters.Remove("callback");
            requestParameters.Remove("asyncState");

            // Remove the word "Begin" from the method name (this is because the method called on the server's side is the one without "Begin")
            if (methodName.StartsWith("Begin")) //should always be the case
            {
                methodName = methodName.Substring(5);
            }

            // Call the server:
            var webMethodsCaller = new CSHTML5_ClientBase <INTERFACE_TYPE> .WebMethodsCaller(clientBase.INTERNAL_RemoteAddressAsString);

            var webMethodAsyncResult = new WebMethodAsyncResult(callback, asyncState);
            webMethodsCaller.BeginCallWebMethod(methodName, typeof(INTERFACE_TYPE), typeof(RETURN_TYPE), requestParameters,
                                                (xmlReturnedFromTheServer) =>
            {
                //-------------------------------
                // After server call has finished (not deserialized yet)
                //-------------------------------
                webMethodAsyncResult.XmlReturnedFromTheServer = xmlReturnedFromTheServer;
                webMethodAsyncResult.Completed();     // This causes a call to "EndCallWebMethod" which will deserialize the response.
            });

            return(webMethodAsyncResult);
#else
            return(null);
#endif
        }
Esempio n. 11
0
 public static void EndCallWebMethod_WithoutReturnValue <INTERFACE_TYPE>(CSHTML5_ClientBase <INTERFACE_TYPE> clientBase, string methodName, Dictionary <string, Tuple <Type, object> > requestParameters) where INTERFACE_TYPE : class
 {
     EndCallWebMethod <object, INTERFACE_TYPE>(clientBase, methodName, requestParameters);
 }
Esempio n. 12
0
        //------------------------------------------
        // WCF METHODS WHICH DO NOT RETURN ANY VALUE
        //------------------------------------------

        public static Task CallWebMethodAsync_WithoutReturnValue <INTERFACE_TYPE>(CSHTML5_ClientBase <INTERFACE_TYPE> clientBase, string methodName, Dictionary <string, Tuple <Type, object> > requestParameters) where INTERFACE_TYPE : class
        {
            // The following call works fine because "Task<object>" inherits from "Task".

            return(CallWebMethodAsync <object, INTERFACE_TYPE>(clientBase, methodName, requestParameters));
        }