public object Invoke(object clientObj, MethodInfo mi, params object[] parameters)
        {
#if (SILVERLIGHT)
            throw new NotSupportedException();
#else
            ResponseHeaders = null;
            ResponseCookies = null;
            WebRequest webReq = null;
            object     reto   = null;
            try
            {
                string useUrl = GetEffectiveUrl(clientObj);
                webReq = GetWebRequest(new Uri(useUrl));
                var req = MakeXmlRpcRequest(webReq, mi, parameters, clientObj, XmlRpcMethod, Id);
                SetProperties(webReq);
                SetRequestHeaders(Headers, webReq);
#if (!COMPACT_FRAMEWORK)
                SetClientCertificates(ClientCertificates, webReq);
#endif
                Stream serStream = null;
                Stream reqStream = null;
                bool   logging   = (RequestEvent != null);
                if (!logging)
                {
                    serStream = reqStream = webReq.GetRequestStream();
                }
                else
                {
                    serStream = new MemoryStream(2000);
                }
                try
                {
                    var serializer = new XmlRpcRequestSerializer(XmlRpcFormatSettings);
                    serializer.SerializeRequest(serStream, req);
                    if (logging)
                    {
                        reqStream          = webReq.GetRequestStream();
                        serStream.Position = 0;
                        Util.CopyStream(serStream, reqStream);
                        reqStream.Flush();
                        serStream.Position = 0;
                        OnRequest(new XmlRpcRequestEventArgs(req.proxyId, req.number,
                                                             serStream));
                    }
                }
                finally
                {
                    if (reqStream != null)
                    {
                        reqStream.Close();
                    }
                }
                var webResp = GetWebResponse(webReq) as HttpWebResponse;
                ResponseCookies = webResp.Cookies;
                ResponseHeaders = webResp.Headers;
                Stream respStm = null;
                Stream deserStream;
                logging = (ResponseEvent != null);
                try
                {
                    respStm = webResp.GetResponseStream();
#if (!COMPACT_FRAMEWORK && !FX1_0)
                    respStm = MaybeDecompressStream(webResp, respStm);
#endif
                    if (!logging)
                    {
                        deserStream = respStm;
                    }
                    else
                    {
                        deserStream = new MemoryStream(2000);
                        Util.CopyStream(respStm, deserStream);
                        deserStream.Flush();
                        deserStream.Position = 0;
                    }
                    if (logging)
                    {
                        OnResponse(new XmlRpcResponseEventArgs(req.proxyId, req.number,
                                                               deserStream));
                        deserStream.Position = 0;
                    }
                    XmlRpcResponse resp = ReadResponse(req, webResp, deserStream);
                    reto = resp.retVal;
                }
                finally
                {
                    if (respStm != null)
                    {
                        respStm.Close();
                    }
                }
            }
            finally
            {
                webReq = null;
            }
            return(reto);
#endif
        }
        private static void GetRequestStreamCallback(IAsyncResult asyncResult)
        {
            var clientResult = (XmlRpcAsyncResult)asyncResult.AsyncState;

            clientResult.CompletedSynchronously = asyncResult.CompletedSynchronously;
            try
            {
                Stream serStream = null;
                Stream reqStream = null;
                bool   logging   = (clientResult.ClientProtocol.RequestEvent != null);
                if (!logging)
                {
                    serStream             = reqStream
                                          = clientResult.Request.EndGetRequestStream(asyncResult);
                }
                else
                {
                    serStream = new MemoryStream(2000);
                }

                try
                {
                    var serializer = new XmlRpcRequestSerializer
                    {
                        UseEmptyElementTags = clientResult.XmlRpcFormatSettings.UseEmptyElementTags,
                        UseEmptyParamsTag   = clientResult.XmlRpcFormatSettings.UseEmptyParamsTag,
                        UseIndentation      = clientResult.XmlRpcFormatSettings.UseIndentation,
                        Indentation         = clientResult.XmlRpcFormatSettings.Indentation,
                        UseIntTag           = clientResult.XmlRpcFormatSettings.UseIntTag,
                        UseStringTag        = clientResult.XmlRpcFormatSettings.UseStringTag
                    };
                    if (clientResult.XmlRpcFormatSettings.XmlEncoding != null)
                    {
                        serializer.XmlEncoding = clientResult.XmlRpcFormatSettings.XmlEncoding;
                    }

                    var req = clientResult.XmlRpcRequest;
                    serializer.SerializeRequest(serStream, req);
                    if (logging)
                    {
                        reqStream          = clientResult.Request.EndGetRequestStream(asyncResult);
                        serStream.Position = 0;
                        Util.CopyStream(serStream, reqStream);
                        reqStream.Flush();
                        serStream.Position = 0;
                        clientResult.ClientProtocol.OnRequest(
                            new XmlRpcRequestEventArgs(req.proxyId, req.number, serStream));
                    }
                }
                finally
                {
                    if (reqStream != null)
                    {
                        reqStream.Close();
                    }
                }
                clientResult.Request.BeginGetResponse(new AsyncCallback(GetResponseCallback), clientResult);
            }
            catch (Exception ex)
            {
                ProcessAsyncException(clientResult, ex);
            }
        }