public void BeginHessianMethodCall(object[] arrMethodArgs, MethodInfo methodInfo, AsyncCallback callback)
        {
            BeginSendRequest(new HessianMethodCall(GetRequestBytes(arrMethodArgs, methodInfo), methodInfo, callback));

            DateTime start = DateTime.Now;

            CHessianLog.AddLogEntry(methodInfo.Name, start, start, 0, 0);
        }
        public void EndHessianMethodCall(HessianMethodCall call)
        {
            DateTime end = DateTime.Now;

            CHessianLog.AddLogEntry(call.methodInfo.Name, end, end, -1, -1);

            // Make it easier for the GC
            call.methodArgs = null;
            call.methodInfo = null;
            call.request    = null;
            call.callback.Invoke(call);
        }
        /// <summary>
        /// This method wrapps an instance call to the hessian
        /// requests, sends it to the hessian service and translates the reply of this call to the C# - data type
        /// </summary>
        /// <param name="methodInfo">The method to call</param>
        /// <param name="arrMethodArgs">The arguments to the method call</param>
        /// <returns>Invocation result</returns>
        public object DoHessianMethodCall(object[] arrMethodArgs, MethodInfo methodInfo)
        {
            Stream sInStream = null, sOutStream = null;

            try
            {
                int      totalBytesRead;
                DateTime start = DateTime.Now;

                byte[] request = GetRequestBytes(arrMethodArgs, methodInfo);

                object result;
                try
                {
                    WebRequest webRequest = SendRequest(request, out sOutStream);
                    result = ReadReply(webRequest, methodInfo, out sInStream, out totalBytesRead);
                }
                catch (Exception e)
                {
                    /*
                     * SocketException se = e.InnerException as SocketException;
                     * WebException we = e as WebException;
                     * if ((se != null && se.SocketErrorCode == SocketError.ConnectionAborted)
                     || (we != null && we.Status == WebExceptionStatus.KeepAliveFailure))
                     */

                    if (!(e is CHessianException))
                    {
                        try
                        {
                            // retry once (Keep-Alive connection closed?)
                            WebRequest webRequest = SendRequest(request, out sOutStream);
                            result = ReadReply(webRequest, methodInfo, out sInStream, out totalBytesRead);
                        }
                        catch (Exception)
                        {
                            // retry again (last time)
                            WebRequest webRequest = SendRequest(request, out sOutStream);
                            result = ReadReply(webRequest, methodInfo, out sInStream, out totalBytesRead);
                        }
                    }
                    else
                    {
                        throw e; // rethrow
                    }
                }

                CHessianLog.AddLogEntry(methodInfo.Name, start, DateTime.Now, totalBytesRead, request.Length);
                return(result);
            }
            catch (CHessianException he)
            {
                if (he.FaultWrapper)
                {
                    // wrapper for a received exception
                    throw he.InnerException;
                }
                else
                {
                    throw he; // rethrow
                }
            }
            finally
            {
                if (sInStream != null)
                {
                    sInStream.Close();
                }
                if (sOutStream != null)
                {
                    sOutStream.Close();
                }
            }
        }