1
0

XmlRpcRequestSerializer.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. namespace Nwc.XmlRpc
  2. {
  3. using System;
  4. using System.Collections;
  5. using System.Xml;
  6. using System.IO;
  7. /// <summary>Class responsible for serializing an XML-RPC request.</summary>
  8. /// <remarks>This class handles the request envelope, depending on <c>XmlRpcSerializer</c>
  9. /// to serialize the payload.</remarks>
  10. /// <seealso cref="XmlRpcSerializer"/>
  11. public class XmlRpcRequestSerializer : XmlRpcSerializer
  12. {
  13. static private XmlRpcRequestSerializer _singleton;
  14. /// <summary>A static singleton instance of this deserializer.</summary>
  15. static public XmlRpcRequestSerializer Singleton
  16. {
  17. get
  18. {
  19. if (_singleton == null)
  20. _singleton = new XmlRpcRequestSerializer();
  21. return _singleton;
  22. }
  23. }
  24. /// <summary>Serialize the <c>XmlRpcRequest</c> to the output stream.</summary>
  25. /// <param name="output">An <c>XmlTextWriter</c> stream to write data to.</param>
  26. /// <param name="obj">An <c>XmlRpcRequest</c> to serialize.</param>
  27. /// <seealso cref="XmlRpcRequest"/>
  28. override public void Serialize(XmlTextWriter output, Object obj)
  29. {
  30. XmlRpcRequest request = (XmlRpcRequest)obj;
  31. output.WriteStartDocument();
  32. output.WriteStartElement(METHOD_CALL);
  33. output.WriteElementString(METHOD_NAME, request.MethodName);
  34. output.WriteStartElement(PARAMS);
  35. foreach (Object param in request.Params)
  36. {
  37. output.WriteStartElement(PARAM);
  38. output.WriteStartElement(VALUE);
  39. SerializeObject(output, param);
  40. output.WriteEndElement();
  41. output.WriteEndElement();
  42. }
  43. output.WriteEndElement();
  44. output.WriteEndElement();
  45. }
  46. }
  47. }