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));
            }
        }
Example #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
        }