cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
3102
Views
1
Helpful
5
Replies
Highlighted
Beginner

C# AXL return 500 internal server error

Hey

I am working on getting a connection for the CUCM version 10.5 in c# the goal is to handle phone settings in a existing project
     - call forward

     - hunt group membership

     - etc

At the moment, I am trying to get access to the information as a start, and see winch kind of information i can get, my problem seems to be in the soap message with a error or mistake I cannot find.

I will be thankful for any help or hint to solve it, my code is below

kind regards
Michael

using System;

using System.IO;

using System.Net;

using System.Net.Security;

using System.Security.Cryptography.X509Certificates;

namespace AXL

{

    internal class Program

    {

        private static void Main(string[] args)

        {

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

       

            req.ProtocolVersion = HttpVersion.Version10;

            req.ContentType = "text/xml; charset=utf-8";

            req.Method = "POST";

            req.Host = "10.10.0.129:8443";

            req.ContentType = "text/xml";

            req.Accept = "text/xml";

            req.Headers.Add("SOAPAction", "CUCM:DB ver=10.5 getPhone");

            string auth = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes("admin:XXXX"));

            req.Headers.Add("Authorization",

                "Basic " + auth);

            string mes;

            mes = "<soapenv:Envelope xmlns:soapenv=";

            mes += "\"http://schemas.xmlsoap.org/soap/envelope/\"";

            mes += " xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\"";

            mes += " xmlns:ns=\"http://www.cisco.com/AXL/API/10.5\"";

            mes += "<soapenv:Header/>";

            mes += "<soapenv:Body>";

            mes += "<ns:getPhone><name>SEPE8B7480316D6</name></ns:getPhone>";

            mes += "</soapenv:Body>";

            mes += "</soapenv:Envelope>";

            System.Net.ServicePointManager.ServerCertificateValidationCallback =

                delegate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)

                {

                    return true;

                };

            req.ContentLength = mes.Length;

            Stream s = req.GetRequestStream();

            byte[] buffer = System.Text.Encoding.UTF8.GetBytes(mes);

            s.Write(buffer, 0, mes.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 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Beginner

Re: C# AXL return 500 internal server error

Meddelelse blev redigeret af: Michael Kjeldsen

after working with fiddler i was able to locate the cous for the error ,

so this is the code i got to work with a cucm 10.5 to infomation in c#

it is not the best looking but are working it a console app

using System;

using System.IO;

using System.Net;

using System.Net.Security;

using System.Security.Cryptography.X509Certificates;

using System.Text;

namespace AXL

{

    internal class Program

    {

        private static void Main(string[] args)

        {

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

           

            req.ProtocolVersion = HttpVersion.Version10;

            req.ContentType = "text/xml; charset=utf-8";

            req.Method = "POST";

            req.Host = "10.10.0.129:8443";

            req.ContentType = "text/xml";

            req.Accept = "text/xml";

            req.Headers.Add("SOAPAction", "CUCM:DB ver=10.5 getPhone");

            req.Timeout = 10000;

            string aut = EncodeTo64("admin:Gyngemose50!");

            string auth = Convert.ToBase64String(System.Text.UTF8Encoding.UTF8.GetBytes("admin:XXXX"));

            req.Headers.Add("Authorization",

                "Basic " + aut);

            string mes;

            mes = "<SOAP-EN:Envelope xmlns:SOAP-EN=";

            mes += "\"http://schemas.xmlsoap.org/soap/envelope/\"";

            mes += " xmlns:ns=\"http://www.cisco.com/AXL/API/10.5\">";

            mes += "<SOAP-EN:Header/>";

            mes += "<SOAP-EN:Body>";

            mes += "<ns:getPhone sequence=\"1\"><name>SEP001E13E61B49</name></ns:getPhone>";

            mes += "</SOAP-EN:Body>";

            mes += "</SOAP-EN:Envelope>";

            System.Net.ServicePointManager.ServerCertificateValidationCallback =

                delegate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)

                {

                    return true;

                };

            req.ContentLength = mes.Length;

            Stream s = req.GetRequestStream();

            byte[] buffer = System.Text.Encoding.UTF8.GetBytes(mes);

            s.Write(buffer, 0, mes.Length);

            s.Close();

            try

            {

                WebResponse resp = req.GetResponse();

                s = resp.GetResponseStream();

                StreamReader sr = new StreamReader(s);

                string outputString = sr.ReadToEnd(); //Just output XML response

                Console.WriteLine((outputString));

                sr.Close();

                s.Close();

                resp.Close();

            }

            catch (Exception ex)

            {

                string excep = ex.ToString();

            }

        }

        public static string EncodeTo64(string toEncode)

        {

            byte[] toEncodeAsBytes = Encoding.UTF8.GetBytes(toEncode);

            string returnValue = Convert.ToBase64String(toEncodeAsBytes);

            return returnValue;

        }

    }

}

View solution in original post

5 REPLIES 5
Highlighted
Beginner

Re: C# AXL return 500 internal server error

Hi,

Normally, when you get an error (500 internal server error). It means your AXL command (getPhone) is not correct.

Please try this

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.cisco.com/AXL/API/10.5">

<soapenv:Header/>

<soapenv:Body>

   <ns:getPhone sequence="1">

       <name>SEPE8B7480316D6</name>

   </ns:getPhone>

</soapenv:Body>

</soapenv:Envelope>

//======================================================

You need to set Authentication (user name and password) and SOAP Action (CUCM:DB ver=10.5)

I hope this will help you.

Regards

Thuy Doan

Highlighted
Beginner

Re: C# AXL return 500 internal server error

Hey Thuy

thanks you for the replay

when I change to SOAP Action (CUCM:DB ver=10.5) , I get a 599 error instead, as a network time-out error, I am not sure how to interpreter it since I changed the time-out 10.000 and still getting the error, so I am pretty sure it is not directly the time-out there is the problem here.

I tried with the following message and settings

  req.ProtocolVersion = HttpVersion.Version10;

            req.ContentType = "text/xml; charset=utf-8";

            req.Method = "POST";

            req.Host = "10.10.0.129:8443";

            req.ContentType = "text/xml";

            req.Accept = "text/xml";

            req.Headers.Add("SOAPAction", "CUCM:DB ver=10.5 getPhone");

            req.Timeout = 10000;

<SOAP-EN:Envelope xmlns:SOAP-EN="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.cisco.com/AXL/API/10.5"<SOAP-EN:Header/>

<SOAP-EN:Body>

      <ns:getPhone sequence="1">

               <name>SEPE8B7480316D6</name>

      </ns:getPhone>

     </SOAP-EN:Body>

</SOAP-EN:Envelope>

regarding the auth , that I can see is not a problem, the first tries result with the error message not 401 Unauthorized, until I did fix it.

kind regards

Michael

Highlighted
Rising star

Re: C# AXL return 500 internal server error

In order to speed things up.. could you run Fiddler before making the request and posting request and response as you see it in fiddler?

As for your authentication generation.. the code I'm using uses UTF-8, not ASCII

public static string EncodeTo64(string toEncode)

        {

            byte[] toEncodeAsBytes = Encoding.UTF8.GetBytes(toEncode);

            string returnValue = Convert.ToBase64String(toEncodeAsBytes);

            return returnValue;

        }

(but I doubt it's that)

It's easier to tell by looking at request and response (takes away from the implementation details which vary by programming language).

Also.. you should properly dispose your streams and readers Again not the reason for your 500 error, but just in case.

Highlighted
Beginner

Re: C# AXL return 500 internal server error

Hey Stephan

thank you for the replay

I tried to change the auth generation, I don't see any change with that, I am pretty sure the auth is working, but yea you never know , regarding the dispose, yea that will come in the working version. It is not the best looking code at the moment

thanks for the hint about fiddler, I have never use it before but rather nice, better the try to finde the stream in wireshark

i tried with fiddler and found the error and problem

i forgot a ">" in the soap header witch was causing the problem with the connection

Highlighted
Beginner

Re: C# AXL return 500 internal server error

Meddelelse blev redigeret af: Michael Kjeldsen

after working with fiddler i was able to locate the cous for the error ,

so this is the code i got to work with a cucm 10.5 to infomation in c#

it is not the best looking but are working it a console app

using System;

using System.IO;

using System.Net;

using System.Net.Security;

using System.Security.Cryptography.X509Certificates;

using System.Text;

namespace AXL

{

    internal class Program

    {

        private static void Main(string[] args)

        {

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

           

            req.ProtocolVersion = HttpVersion.Version10;

            req.ContentType = "text/xml; charset=utf-8";

            req.Method = "POST";

            req.Host = "10.10.0.129:8443";

            req.ContentType = "text/xml";

            req.Accept = "text/xml";

            req.Headers.Add("SOAPAction", "CUCM:DB ver=10.5 getPhone");

            req.Timeout = 10000;

            string aut = EncodeTo64("admin:Gyngemose50!");

            string auth = Convert.ToBase64String(System.Text.UTF8Encoding.UTF8.GetBytes("admin:XXXX"));

            req.Headers.Add("Authorization",

                "Basic " + aut);

            string mes;

            mes = "<SOAP-EN:Envelope xmlns:SOAP-EN=";

            mes += "\"http://schemas.xmlsoap.org/soap/envelope/\"";

            mes += " xmlns:ns=\"http://www.cisco.com/AXL/API/10.5\">";

            mes += "<SOAP-EN:Header/>";

            mes += "<SOAP-EN:Body>";

            mes += "<ns:getPhone sequence=\"1\"><name>SEP001E13E61B49</name></ns:getPhone>";

            mes += "</SOAP-EN:Body>";

            mes += "</SOAP-EN:Envelope>";

            System.Net.ServicePointManager.ServerCertificateValidationCallback =

                delegate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)

                {

                    return true;

                };

            req.ContentLength = mes.Length;

            Stream s = req.GetRequestStream();

            byte[] buffer = System.Text.Encoding.UTF8.GetBytes(mes);

            s.Write(buffer, 0, mes.Length);

            s.Close();

            try

            {

                WebResponse resp = req.GetResponse();

                s = resp.GetResponseStream();

                StreamReader sr = new StreamReader(s);

                string outputString = sr.ReadToEnd(); //Just output XML response

                Console.WriteLine((outputString));

                sr.Close();

                s.Close();

                resp.Close();

            }

            catch (Exception ex)

            {

                string excep = ex.ToString();

            }

        }

        public static string EncodeTo64(string toEncode)

        {

            byte[] toEncodeAsBytes = Encoding.UTF8.GetBytes(toEncode);

            string returnValue = Convert.ToBase64String(toEncodeAsBytes);

            return returnValue;

        }

    }

}

View solution in original post

CreatePlease to create content