コード例 #1
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
        }
コード例 #2
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);
        }
コード例 #3
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);
        }
コード例 #4
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
        }