1

I have a MS Visual C# 2010 XML-RPC client app that uses the CookComputing.XmlRpc library. It works very well when it receives well-formed input. Here are the essential code elements:

using CookComputing.XmlRpc;
...
    public interface IXml : IXmlRpcProxy
    {
        [XmlRpcMethod]
        MyResponse SendRequest(MyRequest request);
    }
...
        // create instance of XML-RPC interface
        IXml proxy = XmlRpcProxyGen.Create<IXml>();
        // set URL to selected end point
        proxy.Url = MyUrl;
        // set the methodName
        proxy.XmlRpcMethod = XmlRpcMethod;
        // set request variables
        MyRequest request;
        string data = txtSend.Text;
        request.Request = data;

        // talk to server and get response
        try
        {
            MyResponse ret = proxy.SendRequest(request);
...
        }
...
        catch (Exception ex)
        {
            txtReceive.ForeColor = Color.Red;
            txtReceive.Text = ex.ToString();
        }

So far, so good. However, I sometimes get a response from the server that is not valid XML-RPC. (I have no control over this.) For example:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
  <head>
    <title>404 Not Found</title>
  </head>
  <body>
    <h1>Not Found</h1>
    <p>The requested URL /ngt_jrn_stg was not found on this server.</p>
  </body>
</html>

When that happens, the CookComputing XML-RPC library returns an error:

CookComputing.XmlRpc.XmlRpcServerException: Not Found
at CookComputing.XmlRpc.XmlRpcClientProtocol.ReadResponse(XmlRpcRequest req, WebResponse webResp, Stream respStm, Type returnType)
at CookComputing.XmlRpc.XmlRpcClientProtocol.Invoke(Object clientObj, MethodInfo mi, Object[] parameters)
at XmlRpcProxyf2e1082a-4493-486e-9034-cea828aa54d4.SendRequest(MyRequest request)
at TestNgt.TestNgt.btnProcess_Click(Object sender, EventArgs e) in ...\Main.cs:line 328

Right now (as you can see in the code above), I catch the error and display the exception text. What I would like to know is if there is a way that I can handle this error more gracefully. Ideally, I would like to display something like "404 Not Found: The requested URL /ngt_jrn_stg was not found on this server." (from the server response HTML).

I trap the error message from XML-RPC call, but I can't find a way to programatically access the actual HTML response that caused the error. (I found the text shown above by setting up a TcpTrace instance on the port I use to communicate with the server.)

Link to XML-RPC.NET Documentation: http://xml-rpc.net/faq/xmlrpcnetfaq-2-5-0.html

  • Well read the docs (you already have the link) about error handling – Sir Rufo Feb 08 '17 at 00:04
  • I did read the documentation, especially Section 4: Error Handling. Maybe I have a blind spot. But, as far I can tell, none of the three cases mentioned shed any light on my circumstances. – Sagebrush Gardener Feb 08 '17 at 00:15
  • 1
    A bit old, but did you found a way to get more information out of the exception being thrown? – FredM Nov 14 '19 at 14:31

0 Answers0