Example #1
0
        /// <summary>
        /// Deserializes an XML-RPC response from a <see cref="System.Xml.XmlReader"/>.
        /// </summary>
        /// <param name="reader">the <see cref="System.Xml.XmlReader"/> to read</param>
        /// <param name="config">the context configuration</param>
        /// <param name="typeSerializerFactory">the <see cref="LX.EasyWeb.XmlRpc.Serializer.ITypeSerializerFactory"/> to get type serializers</param>
        /// <returns>a <see cref="LX.EasyWeb.XmlRpc.IXmlRpcResponse"/> read from the reader</returns>
        /// <exception cref="System.Xml.XmlException">failed parsing the response XML</exception>
        public IXmlRpcResponse ReadResponse(XmlReader reader, IXmlRpcStreamConfig config, ITypeSerializerFactory typeSerializerFactory)
        {
            IXmlRpcResponse response = null;

            do
            {
                reader.Read();
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (!String.IsNullOrEmpty(reader.NamespaceURI) || !XmlRpcSpec.METHOD_RESPONSE_TAG.Equals(reader.LocalName))
                    {
                        throw new XmlException("Expected root element methodResponse, got " + new XmlQualifiedName(reader.LocalName, reader.NamespaceURI));
                    }

                    RecursiveTypeSerializer.ReadToElement(reader);
                    if (String.IsNullOrEmpty(reader.NamespaceURI) && XmlRpcSpec.FAULT_TAG.Equals(reader.LocalName))
                    {
                        response = ReadFaultResponse(reader, config, typeSerializerFactory);
                    }
                    else if (String.IsNullOrEmpty(reader.NamespaceURI) && XmlRpcSpec.PARAMS_TAG.Equals(reader.LocalName))
                    {
                        response = ReadParamReponse(reader, config, typeSerializerFactory);
                    }
                }
            } while (!reader.EOF && (reader.NodeType != XmlNodeType.EndElement || !XmlRpcSpec.METHOD_RESPONSE_TAG.Equals(reader.LocalName)));

            if (response == null)
            {
                throw new XmlRpcException("Invalid XML-RPC response.");
            }

            return(response);
        }
Example #2
0
        /// <summary>
        /// Deserializes an XML-RPC request from a <see cref="System.Xml.XmlReader"/>.
        /// </summary>
        /// <param name="reader">the <see cref="System.Xml.XmlReader"/> to read</param>
        /// <param name="config">the context configuration</param>
        /// <param name="typeSerializerFactory">the <see cref="LX.EasyWeb.XmlRpc.Serializer.ITypeSerializerFactory"/> to get type serializers</param>
        /// <returns>a <see cref="LX.EasyWeb.XmlRpc.IXmlRpcRequest"/> read from the reader</returns>
        /// <exception cref="System.Xml.XmlException">failed parsing the request XML</exception>
        public IXmlRpcRequest ReadRequest(XmlReader reader, IXmlRpcStreamConfig config, ITypeSerializerFactory typeSerializerFactory)
        {
            String methodName = null;
            IList  args       = null;

            do
            {
                reader.Read();
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (!String.IsNullOrEmpty(reader.NamespaceURI) || !XmlRpcSpec.METHOD_CALL_TAG.Equals(reader.LocalName))
                    {
                        throw new XmlException("Expected root element methodCall, got " + new XmlQualifiedName(reader.LocalName, reader.NamespaceURI));
                    }

                    RecursiveTypeSerializer.ReadToElement(reader);
                    methodName = ReadMethodName(reader);
                    RecursiveTypeSerializer.ReadToElement(reader);
                    args = RecursiveTypeSerializer.ReadParams(reader, config, typeSerializerFactory);
                }
            } while (!reader.EOF && (reader.NodeType != XmlNodeType.EndElement || !XmlRpcSpec.METHOD_CALL_TAG.Equals(reader.LocalName)));
            return(new XmlRpcRequest(methodName, args == null ? null : ToArray(args)));
        }