object IInterceptor.Intercept(IInvocation invocation, params object[] args)
        {
            //
            // Only intercept calls to XML-RPC service methods
            if (XmlRpcServiceMethodInfo.IsXmlRpcServiceMethod(invocation.Method))
            {
                IXmlRpcServiceProxy xmlRpcServiceProxy = (IXmlRpcServiceProxy)invocation.InvocationTarget;
                IXmlRpcWebRequest   xmlRpcWebRequest   =
                    xmlRpcServiceProxy.WebRequestFactory.CreateRequest(xmlRpcServiceProxy.ServiceEndpointUri);

                XmlRpcServiceMethodInfo methodInfo =
                    XmlRpcServiceMethodInfo.CreateXmlRpcServiceMethodInfo(invocation.Method);

                xmlRpcSerializer.SerializeRequest(new XmlRpcRequest(methodInfo.Name, args),
                                                  xmlRpcWebRequest.RequestStream);

                using (IXmlRpcWebResponse xmlRpcWebResponse = xmlRpcWebRequest.Invoke())
                {
                    XmlRpcResponse xmlRpcResponse =
                        xmlRpcSerializer.DeserializeResponse(xmlRpcWebResponse.ResponseStream,
                                                             invocation.Method.ReturnType);

                    if (xmlRpcResponse is XmlRpcFaultResponse)
                    {
                        throw new XmlRpcInvocationException(((XmlRpcFaultResponse)xmlRpcResponse).Fault);
                    }

                    return(((XmlRpcSuccessResponse)xmlRpcResponse).ReturnValue);
                } // using
            }     // if
            else
            {
                return(invocation.Proceed(args));
            }
        }
예제 #2
0
        private static void CreateMethodsMethodsInfo(MethodInfo[] methods,
                                                     IDictionary <string, XmlRpcServiceMethodInfo> serviceMethods)
        {
            for (int i = 0; i < methods.GetLength(0); ++i)
            {
                XmlRpcServiceMethodAttribute serviceMethodAttribute =
                    (XmlRpcServiceMethodAttribute)Attribute.GetCustomAttribute(
                        methods[i],
                        typeof(XmlRpcServiceMethodAttribute));

                if (serviceMethodAttribute != null)
                {
                    XmlRpcServiceMethodInfo xmlRpcServiceMethodInfo =
                        XmlRpcServiceMethodInfo.CreateXmlRpcServiceMethodInfo(
                            methods[i]);

                    serviceMethods.Add(xmlRpcServiceMethodInfo.Name, xmlRpcServiceMethodInfo);
                } // if
            }     // for
        }
예제 #3
0
        /// <summary>
        /// Dispatches a request to the XML-RPC service.
        /// </summary>
        /// <param name="xmlRpcServiceContext"></param>
        public void Dispatch(IXmlRpcServiceContext xmlRpcServiceContext)
        {
            XmlRpcRequest           xmlRpcRequest           = DeserializeRequest(xmlRpcServiceContext);
            XmlRpcServiceMethodInfo xmlRpcServiceMethodInfo =
                xmlRpcServiceInfo.GetMethod(xmlRpcRequest.MethodName);

            XmlRpcResponse xmlRpcResponse;

            try
            {
                object returnValue = xmlRpcServiceMethodInfo.Invoke(xmlRpcServiceContext.XmlRpcService,
                                                                    xmlRpcRequest.Parameters);
                xmlRpcResponse = new XmlRpcSuccessResponse(returnValue);
            } // try

            catch (Exception e)
            {
                xmlRpcResponse = new XmlRpcFaultResponse(new XmlRpcFault(0, e.ToString()));
            } // catch

            xmlRpcSerializer.SerializeResponse(xmlRpcResponse, xmlRpcServiceContext.OutputStream);
        }