title: CookComputing XML-RPC.NET C# Client: How to fail gracefully on invalid input?
body: <p>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:</p>
  
  <pre><code>using CookComputing.XmlRpc;
  ...
      public interface IXml : IXmlRpcProxy
      {
          [XmlRpcMethod]
          MyResponse SendRequest(MyRequest request);
      }
  ...
          // create instance of XML-RPC interface
          IXml proxy = XmlRpcProxyGen.Create&lt;IXml&gt;();
          // 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();
          }
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>&lt;!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;title&gt;404 Not Found&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;h1&gt;Not Found&lt;/h1&gt;
      &lt;p&gt;The requested URL /ngt_jrn_stg was not found on this server.&lt;/p&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>When that happens, the CookComputing XML-RPC library returns an error:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>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).</p>
  
  <p>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.)</p>
  
  <p>Link to XML-RPC.NET Documentation: <a href="http://xml-rpc.net/faq/xmlrpcnetfaq-2-5-0.html" rel="nofollow noreferrer">http://xml-rpc.net/faq/xmlrpcnetfaq-2-5-0.html</a></p>