public IList listMethods() { IList methods = new ArrayList(); bool considerExposure; foreach (DictionaryEntry handlerEntry in _server) { considerExposure = XmlRpcExposedAttribute.IsExposed(handlerEntry.Value.GetType()); foreach (var mi in handlerEntry.Value.GetType().GetMembers()) { if (mi.MemberType != MemberTypes.Method) { continue; } if (!((MethodInfo)mi).IsPublic) { continue; } if (considerExposure && !XmlRpcExposedAttribute.IsExposed(mi)) { continue; } methods.Add(handlerEntry.Key + "." + mi.Name); } } return(methods); }
public Object Invoke(Object target) { Type type = target.GetType(); MethodInfo method = type.GetMethod(MethodNameMethod); if (method == null) { throw new XmlRpcException(-2, "Method " + MethodNameMethod + " not found."); } if (XmlRpcExposedAttribute.IsExposed(target.GetType()) && !XmlRpcExposedAttribute.IsExposed(method)) { throw new XmlRpcException(-3, "Method " + MethodNameMethod + " is not exposed."); } Object[] args = new Object[Params.Count]; for (int i = 0; i < Params.Count; i++) { args[i] = Params[i]; } return(method.Invoke(target, args)); }
/// <summary>Invoke a method on a given object.</summary> /// <remarks> /// Using reflection, and respecting the <c>XmlRpcExposed</c> attribute, /// invoke the <paramref>methodName</paramref> method on the <paramref>target</paramref> /// instance with the <paramref>parameters</paramref> provided. All this packages other <c>Invoke</c> methods /// end up calling this. /// </remarks> /// <returns><c>Object</c> the value the invoked method returns.</returns> /// <exception cref="XmlRpcException"> /// If method does not exist, is not exposed, parameters invalid, or invocation /// results in an exception. Note, the <c>XmlRpcException.Code</c> will indicate cause. /// </exception> public static object Invoke(object target, string methodName, IList parameters) { if (target == null) { throw new XmlRpcException(XmlRpcErrorCodes.SERVER_ERROR_METHOD, XmlRpcErrorCodes.SERVER_ERROR_METHOD_MSG + ": Invalid target object."); } var type = target.GetType(); var method = type.GetMethod(methodName); try { if (!XmlRpcExposedAttribute.ExposedMethod(target, methodName)) { throw new XmlRpcException(XmlRpcErrorCodes.SERVER_ERROR_METHOD, XmlRpcErrorCodes.SERVER_ERROR_METHOD_MSG + ": Method " + methodName + " is not exposed."); } } catch (MissingMethodException me) { throw new XmlRpcException(XmlRpcErrorCodes.SERVER_ERROR_METHOD, XmlRpcErrorCodes.SERVER_ERROR_METHOD_MSG + ": " + me.Message); } var args = new object[parameters.Count]; var index = 0; foreach (var arg in parameters) { args[index] = arg; index++; } try { var retValue = method.Invoke(target, args); if (retValue == null) { throw new XmlRpcException(XmlRpcErrorCodes.APPLICATION_ERROR, XmlRpcErrorCodes.APPLICATION_ERROR_MSG + ": Method returned NULL."); } return(retValue); } catch (XmlRpcException e) { throw e; } catch (ArgumentException ae) { Logger.WriteEntry(XmlRpcErrorCodes.SERVER_ERROR_PARAMS_MSG + ": " + ae.Message, LogLevel.Information); var call = methodName + "( "; foreach (var o in args) { call += o.GetType().Name; call += " "; } call += ")"; throw new XmlRpcException(XmlRpcErrorCodes.SERVER_ERROR_PARAMS, XmlRpcErrorCodes.SERVER_ERROR_PARAMS_MSG + ": Arguement type mismatch invoking " + call); } catch (TargetParameterCountException tpce) { Logger.WriteEntry(XmlRpcErrorCodes.SERVER_ERROR_PARAMS_MSG + ": " + tpce.Message, LogLevel.Information); throw new XmlRpcException(XmlRpcErrorCodes.SERVER_ERROR_PARAMS, XmlRpcErrorCodes.SERVER_ERROR_PARAMS_MSG + ": Arguement count mismatch invoking " + methodName); } catch (TargetInvocationException tie) { throw new XmlRpcException(XmlRpcErrorCodes.APPLICATION_ERROR, XmlRpcErrorCodes.APPLICATION_ERROR_MSG + " Invoked method " + methodName + ": " + tie.Message); } }