Esempio n. 1
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. 2
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
        }