/// <summary> /// Invoke the object with the request from the input stream. /// </summary> /// <param name="inHessian">the Hessian input stream</param> /// <param name="outHessian">the Hessian output stream</param> public void invoke(AbstractHessianInput inHessian, AbstractHessianOutput outHessian) { inHessian.StartCall(); MethodInfo methodInf = getMethodInfo(inHessian.Method); //If the method doesn't exist if (methodInf == null) { outHessian.StartReply(); outHessian.WriteFault("NoSuchMethodException", "The service has no method named: " + inHessian.Method, null); outHessian.CompleteReply(); return; } ParameterInfo[] paramInfo = methodInf.GetParameters(); Object[] valuesParam = new Object[paramInfo.Length]; for (int i = 0; i < paramInfo.Length; i++) { valuesParam[i] = inHessian.ReadObject(paramInfo[i].ParameterType); } inHessian.CompleteCall(); Object result = null; try { result = methodInf.Invoke(m_Service, valuesParam); } catch (Exception e) { //TODO: Exception besser behandeln if (e.GetType() == typeof(System.Reflection.TargetInvocationException)) { if (e.InnerException != null) { e = e.InnerException; } } outHessian.StartReply(); outHessian.WriteFault("ServiceException", e.Message, e); outHessian.CompleteReply(); return; } outHessian.StartReply(); outHessian.WriteObject(result); outHessian.CompleteReply(); }
/// <summary> /// Invoke the object with the request from the input stream. /// </summary> /// <param name="inHessian">the Hessian input stream</param> /// <param name="outHessian">the Hessian output stream</param> public void invoke(AbstractHessianInput inHessian, AbstractHessianOutput outHessian) { inHessian.SkipOptionalCall(); // Hessian 1.0 backward compatibility String header; while ((header = inHessian.ReadHeader()) != null) { Object value = inHessian.ReadObject(); //context.addHeader(header, value); } String methodName = inHessian.ReadMethod(); int argLength = inHessian.ReadMethodArgLength(); MethodInfo methodInf = getMethodInfo(methodName + "__" + argLength); if (methodInf == null) { methodInf = getMethodInfo(methodName); } //If the method doesn't exist if (methodInf == null) { outHessian.WriteFault("NoSuchMethodException", EscapeMessage("The service has no method named: " + methodName), null); outHessian.CompleteReply(); return; } ParameterInfo[] paramInfo = methodInf.GetParameters(); Object[] valuesParam = new Object[paramInfo.Length]; if (argLength != paramInfo.Length && argLength >= 0) { outHessian.WriteFault("NoSuchMethod", EscapeMessage("method " + methodInf + " argument length mismatch, received length=" + argLength), null); outHessian.Flush(); return; } for (int i = 0; i < paramInfo.Length; i++) { valuesParam[i] = inHessian.ReadObject(paramInfo[i].ParameterType); } inHessian.CompleteCall(); Object result = null; try { result = methodInf.Invoke(m_Service, valuesParam); } catch (Exception e) { //TODO: Exception besser behandeln //if (e.GetType() == typeof(System.Reflection.TargetInvocationException)) //{ // if (e.InnerException != null) // { // e = e.InnerException; // } //} InvokeErrorCallBack?.Invoke(this, e); //多层InnerException使用GetBaseException()更好。 e = e.GetBaseException(); //outHessian.StartReply(); outHessian.WriteFault("ServiceException", e.Message, e.ToString()); outHessian.Flush(); //outHessian.CompleteReply(); return; } outHessian.StartReply(); outHessian.WriteObject(result); outHessian.CompleteReply(); }