Beispiel #1
0
        public void ParseXmlRpcFaultResponse()
        {
            String xmlrpc = @"
<methodResponse>
   <fault>
      <value>
         <struct>
            <member>
               <name>faultCode</name>
               <value><int>4</int></value>
               </member>
            <member>
               <name>faultString</name>
               <value><string>Too many parameters.</string></value>
               </member>
            </struct>
         </value>
      </fault>
   </methodResponse>
";

            XmlTextReader            reader     = new XmlTextReader(new MemoryStream(Encoding.UTF8.GetBytes(xmlrpc)));
            XmlRpcResponseSerializer serializer = new XmlRpcResponseSerializer();
            IXmlRpcResponse          request    = serializer.ReadResponse(reader, null, new TypeSerializerFactory());

            Assert.IsNull(request.Result);
            Assert.IsNotNull(request.Fault);
            Assert.IsEqualTo(request.Fault.FaultCode, 4);
            Assert.IsEqualTo(request.Fault.FaultString, "Too many parameters.");
        }
Beispiel #2
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);
        }
Beispiel #3
0
        /// <summary>
        /// Serializes an XML-RPC response to a response stream.
        /// </summary>
        /// <param name="responseStream">the <see cref="System.IO.Stream"/> to write</param>
        /// <param name="response">the <see cref="LX.EasyWeb.XmlRpc.IXmlRpcResponse"/> to serialize</param>
        /// <param name="config">the context configuration</param>
        /// <param name="typeSerializerFactory">the <see cref="LX.EasyWeb.XmlRpc.Serializer.ITypeSerializerFactory"/> to get type serializers</param>
        /// <exception cref="System.Xml.XmlException">failed writing the response XML</exception>
        public void WriteResponse(Stream responseStream, IXmlRpcResponse response, IXmlRpcStreamRequestConfig config, ITypeSerializerFactory typeSerializerFactory)
        {
            XmlWriter writer = _xmlWriterFactory.GetXmlWriter(config, responseStream);

            WriteResponse(writer, response, config, typeSerializerFactory);
            writer.Flush();
        }
        /// <summary>
        /// Serializes an XML-RPC response to a <see cref="System.Xml.XmlWriter"/>.
        /// </summary>
        /// <param name="writer">the <see cref="System.Xml.XmlWriter"/> to write</param>
        /// <param name="response">the <see cref="LX.EasyWeb.XmlRpc.IXmlRpcResponse"/> to serialize</param>
        /// <param name="config">the context configuration</param>
        /// <param name="typeSerializerFactory">the <see cref="LX.EasyWeb.XmlRpc.Serializer.ITypeSerializerFactory"/> to get type serializers</param>
        /// <exception cref="System.Xml.XmlException">failed writing the response XML</exception>
        public void WriteResponse(XmlWriter writer, IXmlRpcResponse response, IXmlRpcStreamRequestConfig config, ITypeSerializerFactory typeSerializerFactory)
        {
            writer.WriteStartDocument();
            writer.WriteStartElement(XmlRpcSpec.METHOD_RESPONSE_TAG);

            if (response.Fault == null)
                RecursiveTypeSerializer.WriteParams(writer, config, typeSerializerFactory, response.Result);
            else
                WriteFaultResponse(writer, response.Fault, config, typeSerializerFactory);

            writer.WriteEndElement();
            writer.WriteEndDocument();
        }
Beispiel #5
0
        /// <summary>
        /// Serializes an XML-RPC response to a <see cref="System.Xml.XmlWriter"/>.
        /// </summary>
        /// <param name="writer">the <see cref="System.Xml.XmlWriter"/> to write</param>
        /// <param name="response">the <see cref="LX.EasyWeb.XmlRpc.IXmlRpcResponse"/> to serialize</param>
        /// <param name="config">the context configuration</param>
        /// <param name="typeSerializerFactory">the <see cref="LX.EasyWeb.XmlRpc.Serializer.ITypeSerializerFactory"/> to get type serializers</param>
        /// <exception cref="System.Xml.XmlException">failed writing the response XML</exception>
        public void WriteResponse(XmlWriter writer, IXmlRpcResponse response, IXmlRpcStreamRequestConfig config, ITypeSerializerFactory typeSerializerFactory)
        {
            writer.WriteStartDocument();
            writer.WriteStartElement(XmlRpcSpec.METHOD_RESPONSE_TAG);

            if (response.Fault == null)
            {
                RecursiveTypeSerializer.WriteParams(writer, config, typeSerializerFactory, response.Result);
            }
            else
            {
                WriteFaultResponse(writer, response.Fault, config, typeSerializerFactory);
            }

            writer.WriteEndElement();
            writer.WriteEndDocument();
        }
Beispiel #6
0
        public void ParseXmlRpcResponse()
        {
            String xmlrpc = @"
<methodResponse>
   <params>
      <param>
         <value><string>South Dakota</string></value>
         </param>
      </params>
   </methodResponse>";

            XmlTextReader            reader     = new XmlTextReader(new MemoryStream(Encoding.UTF8.GetBytes(xmlrpc)));
            XmlRpcResponseSerializer serializer = new XmlRpcResponseSerializer();
            IXmlRpcResponse          request    = serializer.ReadResponse(reader, null, new TypeSerializerFactory());

            Assert.IsNull(request.Fault);
            Assert.IsEqualTo(request.Result, "South Dakota");
        }
Beispiel #7
0
        private void WriteResponse(IXmlRpcStreamRequestConfig config, Stream outputStream, IXmlRpcResponse response)
        {
            XmlRpcResponseSerializer serializer = new XmlRpcResponseSerializer();

            if (_xmlWriterFactory != null)
            {
                serializer.XmlWriterFactory = _xmlWriterFactory;
            }
            serializer.WriteResponse(outputStream, response, config, TypeSerializerFactory);
        }
 /// <summary>
 /// Serializes an XML-RPC response to a response stream.
 /// </summary>
 /// <param name="responseStream">the <see cref="System.IO.Stream"/> to write</param>
 /// <param name="response">the <see cref="LX.EasyWeb.XmlRpc.IXmlRpcResponse"/> to serialize</param>
 /// <param name="config">the context configuration</param>
 /// <param name="typeSerializerFactory">the <see cref="LX.EasyWeb.XmlRpc.Serializer.ITypeSerializerFactory"/> to get type serializers</param>
 /// <exception cref="System.Xml.XmlException">failed writing the response XML</exception>
 public void WriteResponse(Stream responseStream, IXmlRpcResponse response, IXmlRpcStreamRequestConfig config, ITypeSerializerFactory typeSerializerFactory)
 {
     XmlWriter writer = _xmlWriterFactory.GetXmlWriter(config, responseStream);
     WriteResponse(writer, response, config, typeSerializerFactory);
     writer.Flush();
 }
 private void WriteResponse(IXmlRpcStreamRequestConfig config, Stream outputStream, IXmlRpcResponse response)
 {
     XmlRpcResponseSerializer serializer = new XmlRpcResponseSerializer();
     if (_xmlWriterFactory != null)
         serializer.XmlWriterFactory = _xmlWriterFactory;
     serializer.WriteResponse(outputStream, response, config, TypeSerializerFactory);
 }