Cook Computing

Trace XML-RPC Response

July 11, 2009 Written by Charles Cook

If you need to see the XML being returned in an XML-RPC response when you are using XML-RPC.NET, attach an event handler to the proxy's ResponseEvent and trace the content of the stream using the Debug class. If you want to see the request XML, use RequestEvent.

using System.Diagnostics;
using System.IO;
using CookComputing.XmlRpc;

public interface IStateName : IXmlRpcProxy
  string GetStateName(int stateNumber);

class Program
  static void Main(string[] args)
    IStateName proxy = XmlRpcProxyGen.Create<IStateName>();
    proxy.ResponseEvent += (sender, e) => Debug.WriteLine(
      new StreamReader(e.ResponseStream).ReadToEnd());
    string name = proxy.GetStateName(1);

If you are using .NET 2.0 use an anonymous method:

    proxy.ResponseEvent += delegate(object sender,
      XmlRpcResponseEventArgs e)
      Debug.WriteLine(new StreamReader(e.ResponseStream).ReadToEnd());