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)));
 }
 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);
       }
 }
 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);
 }
 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;
 }
 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;
 }