Inheritance: IAsyncResult
Exemplo n.º 1
0
        public IAsyncResult BeginInvoke(
            MethodInfo mi,
            object[] parameters,
            object clientObj,
            AsyncCallback callback,
            object outerAsyncState)
        {
            string        useUrl    = GetEffectiveUrl(clientObj);
            WebRequest    webReq    = GetWebRequest(new Uri(useUrl));
            XmlRpcRequest xmlRpcReq = MakeXmlRpcRequest(webReq, mi,
                                                        parameters, clientObj, _xmlRpcMethod, _id);

            SetProperties(webReq);
            SetRequestHeaders(Headers, webReq);
#if (!COMPACT_FRAMEWORK && !SILVERLIGHT)
            SetClientCertificates(ClientCertificates, webReq);
#endif
            XmlRpcAsyncResult asr = new XmlRpcAsyncResult(this, xmlRpcReq, XmlRpcFormatSettings,
                                                          webReq, callback, outerAsyncState, 0);
            webReq.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback),
                                         asr);
            if (!asr.IsCompleted)
            {
                asr.CompletedSynchronously = false;
            }
            return(asr);
        }
Exemplo n.º 2
0
        public IAsyncResult BeginInvoke(
            string methodName,
            object[] parameters,
            object clientObj,
            AsyncCallback callback,
            object outerAsyncState)
        {
            SetUrl(clientObj);
            WebRequest    webReq    = GetWebRequest(new Uri(Url));
            XmlRpcRequest xmlRpcReq = MakeXmlRpcRequest(webReq, methodName,
                                                        parameters, clientObj);

            SetProperties(webReq);
            SetRequestHeaders(headers, webReq);
            SetClientCertificates(clientCertificates, webReq);
            Encoding useEncoding = null;

            if (xmlEncoding != null)
            {
                useEncoding = xmlEncoding;
            }
            XmlRpcAsyncResult asr = new XmlRpcAsyncResult(this, xmlRpcReq,
                                                          useEncoding, _useIndentation, _indentation, webReq, callback,
                                                          outerAsyncState, 0);

            webReq.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), asr);
            if (!asr.IsCompleted)
            {
                asr.CompletedSynchronously = false;
            }
            return(asr);
        }
Exemplo n.º 3
0
        static void ReadAsyncResponseStream(XmlRpcAsyncResult result)
        {
            IAsyncResult asyncResult;

            do
            {
                byte[] buff    = result.Buffer;
                long   contLen = result.Response.ContentLength;
                if (buff == null)
                {
                    if (contLen == -1)
                    {
                        result.Buffer = new Byte[1024];
                    }
                    else
                    {
                        result.Buffer = new Byte[contLen];
                    }
                }
                else
                {
                    if (contLen != -1 && contLen > result.Buffer.Length)
                    {
                        result.Buffer = new Byte[contLen];
                    }
                }
                buff        = result.Buffer;
                asyncResult = result.ResponseStream.BeginRead(buff, 0, buff.Length,
                                                              new AsyncCallback(ReadResponseCallback), result);
                if (!asyncResult.CompletedSynchronously)
                {
                    return;
                }
            }while (!(ProcessAsyncResponseStreamResult(result, asyncResult)));
        }
Exemplo n.º 4
0
        static bool ProcessAsyncResponseStreamResult(XmlRpcAsyncResult result,
                                                     IAsyncResult asyncResult)
        {
            int  endReadLen = result.ResponseStream.EndRead(asyncResult);
            long contLen    = result.Response.ContentLength;
            bool completed;

            if (endReadLen == 0)
            {
                completed = true;
            }
            else if (contLen > 0 && endReadLen == contLen)
            {
                result.ResponseBufferedStream = new MemoryStream(result.Buffer);
                completed = true;
            }
            else
            {
                if (result.ResponseBufferedStream == null)
                {
                    result.ResponseBufferedStream = new MemoryStream(result.Buffer.Length);
                }
                result.ResponseBufferedStream.Write(result.Buffer, 0, endReadLen);
                completed = false;
            }
            if (completed)
            {
                result.Complete();
            }
            return(completed);
        }
Exemplo n.º 5
0
        static void GetRequestStreamCallback(IAsyncResult asyncResult)
        {
            XmlRpcAsyncResult clientResult
                = (XmlRpcAsyncResult)asyncResult.AsyncState;

            clientResult.CompletedSynchronously = asyncResult.CompletedSynchronously;
            try
            {
                Stream stm = clientResult.Request.EndGetRequestStream(asyncResult);
                try
                {
                    XmlRpcRequest    req        = clientResult.XmlRpcRequest;
                    XmlRpcSerializer serializer = new XmlRpcSerializer();
                    if (clientResult.XmlEncoding != null)
                    {
                        serializer.XmlEncoding = clientResult.XmlEncoding;
                    }
                    serializer.UseIndentation = clientResult.UseIndentation;
                    serializer.Indentation    = clientResult.Indentation;
                    serializer.SerializeRequest(stm, req);
                }
                finally
                {
                    stm.Close();
                }
                clientResult.Request.BeginGetResponse(new AsyncCallback(GetResponseCallback), clientResult);
            }
            catch (Exception ex)
            {
                ProcessAsyncException(clientResult, ex);
            }
        }
Exemplo n.º 6
0
        public IAsyncResult BeginInvoke(
            MethodInfo mi,
            object[] parameters,
            object clientObj,
            AsyncCallback callback,
            object outerAsyncState)
        {
            string        useUrl    = GetEffectiveUrl(clientObj);
            WebRequest    webReq    = GetWebRequest(new Uri(useUrl));
            XmlRpcRequest xmlRpcReq = MakeXmlRpcRequest(webReq, mi,
                                                        parameters, clientObj, _xmlRpcMethod, _id);

            SetProperties(webReq);
            SetRequestHeaders(_headers, webReq);
#if (!COMPACT_FRAMEWORK)
            SetClientCertificates(_clientCertificates, webReq);
#endif
            Encoding useEncoding = null;
            if (_xmlEncoding != null)
            {
                useEncoding = _xmlEncoding;
            }
            XmlRpcAsyncResult asr = new XmlRpcAsyncResult(this, xmlRpcReq,
                                                          useEncoding, _useEmptyParamsTag, _useIndentation, _indentation,
                                                          _useIntTag, _useStringTag, webReq, callback, outerAsyncState, 0);
            webReq.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback),
                                         asr);
            if (!asr.IsCompleted)
            {
                asr.CompletedSynchronously = false;
            }
            return(asr);
        }
Exemplo n.º 7
0
        static void GetRequestStreamCallback(IAsyncResult asyncResult)
        {
            XmlRpcAsyncResult 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
                {
                    XmlRpcRequest    req        = clientResult.XmlRpcRequest;
                    XmlRpcSerializer serializer = new XmlRpcSerializer();
                    if (clientResult.XmlEncoding != null)
                    {
                        serializer.XmlEncoding = clientResult.XmlEncoding;
                    }
                    serializer.UseEmptyParamsTag = clientResult.UseEmptyParamsTag;
                    serializer.UseIndentation    = clientResult.UseIndentation;
                    serializer.Indentation       = clientResult.Indentation;
                    serializer.UseIntTag         = clientResult.UseIntTag;
                    serializer.UseStringTag      = clientResult.UseStringTag;
                    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);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="asr"></param>
        /// <param name="returnType"></param>
        /// <returns></returns>
        public object EndInvoke(IAsyncResult asr, Type returnType)
        {
            object reto           = null;
            Stream responseStream = null;

            try
            {
                XmlRpcAsyncResult clientResult = (XmlRpcAsyncResult)asr;
                if (clientResult.Exception != null)
                {
                    throw clientResult.Exception;
                }
                if (clientResult.EndSendCalled)
                {
                    throw new Exception("dup call to EndSend");
                }
                clientResult.EndSendCalled = true;
                if (clientResult.XmlRpcRequest != null && returnType != null)
                {
                    clientResult.XmlRpcRequest.ReturnType = returnType;
                }
                HttpWebResponse webResp = (HttpWebResponse)clientResult.WaitForResponse();
#if (!COMPACT_FRAMEWORK && !SILVERLIGHT)
                clientResult._responseCookies = webResp.Cookies;
                clientResult._responseHeaders = webResp.Headers;
#endif
                responseStream = clientResult.ResponseBufferedStream;
                if (ResponseEvent != null)
                {
                    OnResponse(new XmlRpcResponseEventArgs(
                                   clientResult.XmlRpcRequest.proxyId,
                                   clientResult.XmlRpcRequest.number,
                                   responseStream));
                    responseStream.Position = 0;
                }
#if (!COMPACT_FRAMEWORK && !FX1_0 && !SILVERLIGHT)
                responseStream = MaybeDecompressStream((HttpWebResponse)webResp,
                                                       responseStream);
#endif
                XmlRpcResponse resp = ReadResponse(clientResult.XmlRpcRequest,
                                                   webResp, responseStream);
                reto = resp.retVal;
            }
            finally
            {
                if (responseStream != null)
                {
                    responseStream.Close();
                }
            }
            return(reto);
        }
Exemplo n.º 9
0
        static void ProcessAsyncException(XmlRpcAsyncResult clientResult, Exception ex)
        {
            WebException webex = ex as WebException;

            if (webex != null && webex.Response != null)
            {
                clientResult.Response = webex.Response;
                return;
            }
            if (clientResult.IsCompleted)
            {
                throw new Exception("error during async processing");
            }
            clientResult.Complete(ex);
        }
Exemplo n.º 10
0
        void StateNameCallbackNoState(IAsyncResult asr)
        {
            XmlRpcAsyncResult clientResult = (XmlRpcAsyncResult)asr;
            IStateName        proxy        = (IStateName)clientResult.ClientProtocol;

            try
            {
                _ret = proxy.EndGetStateName(asr);
            }
            catch (Exception ex)
            {
                _excep = ex;
            }
            _evt.Set();
        }
Exemplo n.º 11
0
        void StateNameCallback(IAsyncResult asr)
        {
            XmlRpcAsyncResult clientResult = (XmlRpcAsyncResult)asr;
            IStateName        proxy        = (IStateName)clientResult.ClientProtocol;
            CBInfo            info         = (CBInfo)asr.AsyncState;

            try
            {
                info._ret = proxy.EndGetStateName(asr);
            }
            catch (Exception ex)
            {
                info._excep = ex;
            }
            info._evt.Set();
        }
Exemplo n.º 12
0
 static void ReadAsyncResponse(XmlRpcAsyncResult result)
 {
     if (result.Response.ContentLength == 0)
     {
         result.Complete();
         return;
     }
     try
     {
         result.ResponseStream = result.Response.GetResponseStream();
         ReadAsyncResponseStream(result);
     }
     catch (Exception ex)
     {
         ProcessAsyncException(result, ex);
     }
 }
Exemplo n.º 13
0
        static void GetResponseCallback(IAsyncResult asyncResult)
        {
            XmlRpcAsyncResult result = (XmlRpcAsyncResult)asyncResult.AsyncState;

            result.CompletedSynchronously = asyncResult.CompletedSynchronously;
            try
            {
                result.Response = result.ClientProtocol.GetWebResponse(result.Request, asyncResult);
            }
            catch (Exception ex)
            {
                ProcessAsyncException(result, ex);
                if (result.Response == null)
                {
                    return;
                }
            }
            ReadAsyncResponse(result);
        }
Exemplo n.º 14
0
        public object EndInvoke(
            IAsyncResult asr,
            Type returnType)
        {
            object      reto           = null;
            WebResponse webResp        = null;
            Stream      responseStream = null;

            try
            {
                XmlRpcAsyncResult clientResult = (XmlRpcAsyncResult)asr;
                if (clientResult.Exception != null)
                {
                    throw clientResult.Exception;
                }
                if (clientResult.EndSendCalled)
                {
                    throw new Exception("dup call to EndSend");
                }
                clientResult.EndSendCalled = true;
                webResp        = clientResult.WaitForResponse();
                responseStream = clientResult.ResponseBufferedStream;

                XmlRpcResponse resp = ReadResponse(clientResult.XmlRpcRequest,
                                                   webResp, responseStream, returnType);
                reto = resp.retVal;
            }
            finally
            {
                if (responseStream != null)
                {
                    responseStream.Close();
                }
                if (webResp != null)
                {
                    webResp = null;
                }
            }
            return(reto);
        }
Exemplo n.º 15
0
        static void ReadResponseCallback(IAsyncResult asyncResult)
        {
            XmlRpcAsyncResult result = (XmlRpcAsyncResult)asyncResult.AsyncState;

            result.CompletedSynchronously = asyncResult.CompletedSynchronously;
            if (asyncResult.CompletedSynchronously)
            {
                return;
            }
            try
            {
                bool completed = ProcessAsyncResponseStreamResult(result, asyncResult);
                if (!completed)
                {
                    ReadAsyncResponseStream(result);
                }
            }
            catch (Exception ex)
            {
                ProcessAsyncException(result, ex);
            }
        }
Exemplo n.º 16
0
 static void ReadAsyncResponseStream(XmlRpcAsyncResult result)
 {
     IAsyncResult asyncResult;
     do
     {
         byte[] buff = result.Buffer;
         long contLen = result.Response.ContentLength;
         if (buff == null)
         {
             if (contLen == -1)
                 result.Buffer = new Byte[1024];
             else
                 result.Buffer = new Byte[contLen];
         }
         else
         {
             if (contLen != -1 && contLen > result.Buffer.Length)
                 result.Buffer = new Byte[contLen];
         }
         buff = result.Buffer;
         asyncResult = result.ResponseStream.BeginRead(buff, 0, buff.Length,
           new AsyncCallback(ReadResponseCallback), result);
         if (!asyncResult.CompletedSynchronously)
             return;
     }
     while (!(ProcessAsyncResponseStreamResult(result, asyncResult)));
 }
Exemplo n.º 17
0
 static void ReadAsyncResponse(XmlRpcAsyncResult result)
 {
     if (result.Response.ContentLength == 0)
     {
         result.Complete();
         return;
     }
     try
     {
         result.ResponseStream = result.Response.GetResponseStream();
         ReadAsyncResponseStream(result);
     }
     catch (Exception ex)
     {
         ProcessAsyncException(result, ex);
     }
 }
Exemplo n.º 18
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="mi"></param>
        /// <param name="parameters"></param>
        /// <param name="clientObj"></param>
        /// <param name="callback"></param>
        /// <param name="outerAsyncState"></param>
        /// <returns></returns>
        public IAsyncResult BeginInvoke(
          MethodInfo mi,
          object[] parameters,
          object clientObj,
          AsyncCallback callback,
          object outerAsyncState)
        {
            string useUrl = GetEffectiveUrl(clientObj);
            WebRequest webReq = GetWebRequest(new Uri(useUrl));
            XmlRpcRequest xmlRpcReq = MakeXmlRpcRequest(webReq, mi,
              parameters, clientObj, _xmlRpcMethod, _id);
            SetProperties(webReq);
            SetRequestHeaders(Headers, webReq);
#if (!COMPACT_FRAMEWORK && !SILVERLIGHT)
            SetClientCertificates(ClientCertificates, webReq);
#endif
            XmlRpcAsyncResult asr = new XmlRpcAsyncResult(this, xmlRpcReq, XmlRpcFormatSettings,
              webReq, callback, outerAsyncState, 0);
            webReq.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback),
              asr);
            if (!asr.IsCompleted)
                asr.CompletedSynchronously = false;
            return asr;
        }
Exemplo n.º 19
0
 static bool ProcessAsyncResponseStreamResult(XmlRpcAsyncResult result,
   IAsyncResult asyncResult)
 {
     int endReadLen = result.ResponseStream.EndRead(asyncResult);
     long contLen = result.Response.ContentLength;
     bool completed;
     if (endReadLen == 0)
         completed = true;
     else if (contLen > 0 && endReadLen == contLen)
     {
         result.ResponseBufferedStream = new MemoryStream(result.Buffer);
         completed = true;
     }
     else
     {
         if (result.ResponseBufferedStream == null)
         {
             result.ResponseBufferedStream = new MemoryStream(result.Buffer.Length);
         }
         result.ResponseBufferedStream.Write(result.Buffer, 0, endReadLen);
         completed = false;
     }
     if (completed)
         result.Complete();
     return completed;
 }
Exemplo n.º 20
0
 static void ProcessAsyncException(XmlRpcAsyncResult clientResult,
   Exception ex)
 {
     WebException webex = ex as WebException;
     if (webex != null && webex.Response != null)
     {
         clientResult.Response = webex.Response;
         return;
     }
     if (clientResult.IsCompleted)
         throw new Exception("error during async processing");
     clientResult.Complete(ex);
 }
Exemplo n.º 21
0
    public IAsyncResult BeginInvoke(
      MethodInfo mi,
      object[] parameters,
      object clientObj,
      AsyncCallback callback,
      object outerAsyncState)
    {
      string useUrl = GetEffectiveUrl(clientObj);
      WebRequest webReq = GetWebRequest(new Uri(useUrl));
      XmlRpcRequest xmlRpcReq = MakeXmlRpcRequest(webReq, mi,
        parameters, clientObj, _xmlRpcMethod, _id);
      SetProperties(webReq);
#if (!SILVERLIGHT)
      SetRequestHeaders(_headers, webReq);
#endif
#if (!COMPACT_FRAMEWORK &&!SILVERLIGHT)
      SetClientCertificates(_clientCertificates, webReq);
#endif
      Encoding useEncoding = null;
      if (_xmlEncoding != null)
        useEncoding = _xmlEncoding;
      XmlRpcAsyncResult asr = new XmlRpcAsyncResult(this, xmlRpcReq,
        useEncoding, _useEmptyParamsTag, _useIndentation, _indentation, 
        _useIntTag, _useStringTag, webReq, callback, outerAsyncState, 0);
      webReq.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback),
        asr);
      if (!asr.IsCompleted)
        asr.CompletedSynchronously = false;
      return asr;
    }