Cisco Unified Call Manager (CUCM) AXL API throwing error when used in C#.net project

2.3k views Asked by At

I am trying to run a SQL query through AXL API in CUCM sandbox environment from my application and get back the SQL query result. Can anyone please let me know how we can do it through an example. I have attempted to do this, but getting an error "The underlying connection was closed: An unexpected error occurred on a receive" when WebResponse resp = req.GetResponse(); is executed. Full code is shown below:

        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(@"https://xx.xx.xx.xx/https/0/xx.xx.xx.x/axl/");

        //req.KeepAlive = false;
        req.ProtocolVersion = HttpVersion.Version10;

        req.Method = "POST";
        req.Host = "xx.xx.xx.x:8443";
        req.ProtocolVersion = System.Net.HttpVersion.Version10;
        req.ContentType = "text/xml";
        req.Accept = "text/xml";
        req.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes("username:password")));

        string strAXLRequest;
        strAXLRequest = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=";
        strAXLRequest += "\"http://schemas.xmlsoap.org/soap/envelope/\"";
        strAXLRequest += " xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\"";
        strAXLRequest += " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"";
        strAXLRequest += " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"> ";
        strAXLRequest += "<SOAP-ENV:Body> ";
        strAXLRequest += "<m:executeSQLQuery xmlns:m=\"http://www.cisco.com/AXL/API/7.0\" sequence=\"1\"> ";
        strAXLRequest += "<m:sql> ";
        strAXLRequest += "SELECT * FROM Device ";
        strAXLRequest += "</m:sql> ";
        strAXLRequest += "</m:executeSQLQuery> ";
        strAXLRequest += "</SOAP-ENV:Body> ";
        strAXLRequest += "</SOAP-ENV:Envelope>";

        System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };


        req.ContentLength = strAXLRequest.Length;

        Stream s = req.GetRequestStream();
        byte[] buffer = System.Text.Encoding.UTF8.GetBytes(strAXLRequest);
        s.Write(buffer, 0, strAXLRequest.Length);
        s.Close();
        try
        {
            WebResponse resp = req.GetResponse();

        s = resp.GetResponseStream();
        StreamReader sr = new StreamReader(s);
        string outputString = sr.ReadToEnd(); //Just output XML response
        sr.Close();
        s.Close();
        resp.Close();
        }
        catch (Exception ex)
        {
            string excep = ex.ToString();
        }
    }

}

}

1

There are 1 answers

0
Sandeep K S On BEST ANSWER

I solved this. I just had to replace couple of thing:

  1. HttpWebRequest req = (HttpWebRequest)WebRequest.Create(@"https://xx.xx.xx.xx/https/0/xx.xx.xx.x/axl/");

with

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(@"https://xx.xx.xx.x:8443/axl/");

  1. Change my strAXLRequest to

    strAXLRequest += " <soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns=\"http://www.cisco.com/AXL/API/10.0\">"; strAXLRequest += " <soapenv:Header/>"; strAXLRequest += " <soapenv:Body>"; strAXLRequest += " <ns:executeSQLQuery sequence=\"?\">"; //strAXLRequest += " <sql>select * from device </sql>"; strAXLRequest += " <sql>" + SQLQuery + "</sql>"; strAXLRequest += " </ns:executeSQLQuery>"; strAXLRequest += " </soapenv:Body>"; strAXLRequest += " </soapenv:Envelope>";