/// <summary>
        /// This reflective method for invoking methods. Overriden from RealProxy.
        /// Handles the object invocation. 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
        /// <see cref="System.Runtime.Remoting.Proxies.RealProxy"/>
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public override IMessage Invoke(IMessage msg)
        {
            // Convert to a MethodCallMessage
            IMethodCallMessage methodMessage = new MethodCallMessageWrapper((IMethodCallMessage)msg);
            MethodInfo         methodInfo    = this.GetMethodInfoForMethodBase(methodMessage);

            Type[] argumentTypes  = CHessianMethodCaller.GetArgTypes(methodMessage.Args);
            object objReturnValue = null;

            if (methodInfo != null)
            {
                if (methodInfo.Name.Equals("Equals") && argumentTypes != null &&
                    argumentTypes.Length == 1 && argumentTypes[0].IsAssignableFrom((typeof(Object))))
                {
                    Object value = methodMessage.Args[0];
                    if (value == null)
                    {
                        objReturnValue = false;
                    }
                    else if (value.GetType().Equals(typeof(CHessianProxy)) ||
                             value.GetType().IsAssignableFrom(typeof(CHessianProxy)))
                    {
                        objReturnValue = this.m_methodCaller.URI.Equals(((CHessianProxy)value).URI);
                    }
                    else
                    {
                        objReturnValue = false;
                    }
                }
                else if (methodInfo.Name.Equals("GetHashCode") && argumentTypes.Length == 0)
                {
                    objReturnValue = this.m_methodCaller.URI.GetHashCode();
                }
                else if (methodInfo.Name.Equals("GetHessianURL"))
                {
                    objReturnValue = this.m_methodCaller.URI.ToString();
                }
                else if (methodInfo.Name.Equals("ToString") && argumentTypes.Length == 0)
                {
                    objReturnValue = "[HessianProxy " + this.m_methodCaller.URI + "]";
                }
                else if (methodInfo.Name.Equals("GetType") && argumentTypes.Length == 0)
                {
                    objReturnValue = this.m_proxyType;
                }
                else
                {
                    objReturnValue = this.m_methodCaller.DoHessianMethodCall(methodMessage.Args, methodInfo);
                }
            }
            else
            {
                if (methodMessage.MethodName.Equals("GetType") && (methodMessage.ArgCount == 0))
                {
                    objReturnValue = this.m_proxyType;
                }
            }
            // Create the return message (ReturnMessage)
            return(new ReturnMessage(objReturnValue, methodMessage.Args, methodMessage.ArgCount, methodMessage.LogicalCallContext, methodMessage));
        }
 /// <summary>
 /// Gets method info instance, according to the given method base
 /// </summary>
 /// <param name="methodMessage">Method message, that describes the method call</param>
 /// <returns>MethodInfo - Instance</returns>
 private MethodInfo GetMethodInfoForMethodBase(IMethodCallMessage methodMessage)
 {
     if (IsMethodNameUnique(methodMessage.MethodName))
     {
         return(this.m_proxyType.GetMethod(methodMessage.MethodName));
     }
     else
     {
         return(this.m_proxyType.GetMethod(methodMessage.MethodName, CHessianMethodCaller.GetArgTypes(methodMessage.Args)));
     }
 }