cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1293
Views
0
Helpful
15
Replies

Retrieve Data from CUCM 6.x in an XML file using WebService

kevindesai
Level 1
Level 1

Hi,

Can anyone please help me on how to retrieve data from CUCM database using a WebService , e.g. User information such as First Name, Last Name, Phone Extension and Department in an XML format and display that information on a webpage in ASP.NET2.0(C#).

Thanks.

15 Replies 15

msabir
Level 4
Level 4

There is sample code in SDK, both for C# and Java. You basically want to use RisPort web service and it's WSDL is also available on CUCM itslef. I am not much familiar with ASP.NET, but in Eclipse/NetBeans, all you have to do is to load WSDL file and it creates all the code for you. You can just use the stub classes to call the web service. There is probably similar or even easier way in ASP.NET/VisualStudio.Net.

Thanks msabir for your help.

I have already installed WSDL for .NET and also made the following changes based on the documentation (CUCM 6.0)

1. created a public class derived from System.Net.ICertificatePolicy (Method of BruteForcePolicy )

--------------------------------------------

public bool CheckValidationResult(System.Net.ServicePoint sp, System.Security.Cryptography.X509Certificates.X509Certificate cert,

System.Net.WebRequest request, int problem)

{

return true;

}

--------------------------------------------

2. Modified the AXLAPIService constructor

--------------------------------------------

public AXLAPIService(string ccmIp, string user, string password) {

System.Net.ServicePointManager.CertificatePolicy = new BruteForcePolicy();

this.Url = "https://" + ccmIp + ":8443/axl/";

}

--------------------------------------------

3. Overriden the GetWebRequest method

--------------------------------------------

protected override System.Net.WebRequest GetWebRequest(Uri uri){

System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)base.GetWebRequest(uri);

if (this.PreAuthenticate){

System.Net.NetworkCredential nc = this.Credentials.GetCredential(uri, "Basic");

if (nc != null) {

byte[] credBuf = new System.Text.UTF8Encoding().GetBytes(nc.UserName + ":" + nc.Password);

request.Headers["Authorization"] = "Basic" + Convert.ToBase64String(credBuf);

}

}

return request;

}

--------------------------------------------

Also made changes in

public XUserUserGroupUserRolesUserRole[] userRoles;

The following function call instantiate the AXLAPIService object, just to check if there is a connection between the client (webpage) and CUCM Database.

public void axlTest()

{

sUserID = txtUserID.Text.Trim().ToString();

sPassword = txtPassword.Text.Trim().ToString();

AXLAPIService oAXL = new AXLAPIService(ccmServer, sUserID, sPassword);

ListDeviceByNameAndClassReq phoneByName = new ListDeviceByNameAndClassReq();

phoneByName.searchString = "SEP%";

ListDeviceResDevice[] phones = oAXL.listDeviceByNameAndClass(phoneByName).@return;

foreach (ListDeviceResDevice phone in phones) {

lstResult.Items.Add(phone.uuid);

lstResult.Items.Add(phone.name);

}

}

When I debugg the above code I get the message saying "Connecting to the server machine 172.0.1.1 failed. This may be because the machine doesn't exist or a firewall is preventing communication to the remote computer".

However I can able to access the web admin interface from the same machine. And also able to telnet the remote machine.

Could you please help me identify where exactly the problem is or what is it that I'm doing wrong?

Thanks a lot!

Can you start Wireshark and trace what is happening communication wise? When there's a connect problem that's usually an easy way to figure out any errors

Thanks Stephan for your reply.

The Call Manager Host is on the same hub as the client machine (ASP.NET2.0). I can access the web admin page and also I've tried telnet the CUCM host machine on port 8443 and its working fine.

I'd still do the wireshark trace.. by the looks of it there won't be any connection setup at all and you'd see that right away with a wireshark trace.

I've tried with the wireshark, and it looks like there is a connection between the client(source) and cucm host(destination).

What I'd like to point out is, CUCM is installed on a VMWare which actually runs on a Windows XP machine. I have set the static IP for the VMWare(172.20.0.80) and the actual machine's IP is (172.20.1.99). When I telnet/ping/wireshark on 172.20.0.80 it is working fine. I have disabled the proxy settings and in the windows hosts file entered 172.20.0.80 so that it connects to the cucm host machine, still I'm getting the error message BAD REQUEST 400.

Well.. a 400 response is something else entirely than being unable to connect ;)

Now the best thing would be to dump the soap message and verify that it's valid (you can easily do that by saving the text as xml file and opening it in internet explorer), then verify that the syntax is valid (verify against the schema).

Also, there are AXL traces on the CCM which you can download using the RTMT (that's one of the plugins you can download from ccmadmin). If all that tells you nothing, ask the guy who set up your CCM as this part is more in their domain.

I've tried with the SOAP Request and I'm still getting the same error. "BAD REQUEST 400".

I've tried with the following code:

---------------------------------------------

public string SOAPRequest() {

string strAXLRequest = string.Empty;

string AXLHeader = string.Empty;

string strAuthentication = string.Empty;

string strUriHttps = @"https://ccmserver:8443/axl";

string rep = string.Empty;

try {

ServicePointManager.ServerCertificateValidationCallback += delegate { return true; };

HttpWebRequest oWRequest = (HttpWebRequest)HttpWebRequest.Create(new Uri(strUriHttps));

oWRequest.Method = "POST";

oWRequest.ContentType = "text/xml";

strAuthentication = txtUserID.Text.Trim() + ":" + txtPassword.Text.Trim();

strAXLRequest = "http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2000/10/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/1999/XMLSchema\"> ";

strAXLRequest += " ";

strAXLRequest += "http://www.cisco.com/AXL/1.0\" xsi:schemaLocation=\"http://www.cisco.com/AXL/1.0 http://ccmserver/schema/axlsoap.xsd\" sequence=\"1234\"> ";

strAXLRequest += "SEP001CEEEBCEBE ";

strAXLRequest += " ";

strAXLRequest += " ";

strAXLRequest += " ";

strAuthentication = Convert.ToBase64String(Encoding.ASCII.GetBytes(strAuthentication));

AXLHeader = "POST /axl/ HTTP/1.0\r\n";

AXLHeader += "Host:ccmserver:8443\r\n";

AXLHeader += "Authorization: Basic " + strAuthentication + "\r\n";

AXLHeader += "Accept: text/*\r\n";

AXLHeader += "Content-type: text/xml\r\n";

AXLHeader += "SOAPAction: \"CUCM:DB ver=6.0\"\r\n";

AXLHeader += "Content-length: " + strAXLRequest.Length.ToString() + "\r\n\r\n";

AXLHeader += strAXLRequest;

Stream stream = oWRequest.GetRequestStream();

stream.Write(System.Text.Encoding.ASCII.GetBytes(AXLHeader), 0, AXLHeader.Length);

stream.Close();

HttpWebResponse oWResponse = (HttpWebResponse)oWRequest.GetResponse();

Stream recStream = oWResponse.GetResponseStream();

StreamReader readStream = new StreamReader(recStream, Encoding.UTF8);

rep = readStream.ReadToEnd();

}

catch (Exception ex){

lblMessage.Text = ex.Message.ToString();

}

return rep;

}

now I'm getting 401 error. I'm trying with the code copied in my previous post.

Well.. 401 is good.. that means the login/password you use is not correct. To get started, use the same credentials as you use to login to ccmadmin to administrate the server.

I'm using the same login for ccmadmin i.e. the one for Web Admin Interface.

could you please help what is the following line for

because in the CUCM user guide sample there is some key is given ,

------------------------------------------

"Authorization: Basic " + strAuthentication + "\r\n"; --- [strAuthentication is username and passcode]

--------------------------------------------

and also do I have to provide https://ccmserverIP:8443/schema/axlsoap.xsd

in the following statement or only http://ccmserverIP/schema/axlsoap.xsd

"http://www.cisco.com/AXL/1.0\" xsi:schemaLocation=\"http://www.cisco.com/AXL/1.0 http://ccmserver/schema/axlsoap.xsd\" sequence=\"1234\"> ";

really appreciate your efforts.

Thanks.

You don't need to add the port.. I know you're not using Java but since it's similar here are my two methods that generate the data to be sent, and send the data.. perhaps you can adapt them.

You'll see that I'm not really sending the same thing as in the developer guide (the guide seems a bit weird that way.. I just took the working axl class from the ip phone sdk and adapted and optimized it until I got to this point here.. I've used that code for various ccm5 and 6 releases and it always works fine).

public String sendRequest(String axlRequest, String axlParams, boolean utf8) throws CommunicationException

{

StringBuffer HTTPBuffer = new StringBuffer();

try

{

String sAXLRequest = generateAXLRequest(axlRequest, axlParams);

tracer.Trace("AXL request: " + sAXLRequest, 5);

URL url = new URL(this.apiPath);

HttpsURLConnection conn = (HttpsURLConnection)url.openConnection ();

conn.setDoInput(true);

conn.setDoOutput(true);

conn.setFollowRedirects(true);

conn.setRequestMethod("POST");

conn.setRequestProperty("Content-Type", "text/xml");

conn.setRequestProperty("Content-Length", "" + sAXLRequest.length());

conn.setRequestProperty("Authorization", "Basic " + this.authentication);

String databaseVersion = getDatabaseVersion(this.getVersion());

if (databaseVersion != null)

conn.setRequestProperty("SOAPAction", databaseVersion);

conn.connect();

PrintWriter pout = new PrintWriter(new OutputStreamWriter(conn.getOutputStream(), "UTF-8"), true);

pout.print(sAXLRequest);

pout.flush();

int status = conn.getResponseCode();

if (status >= 400) // we have an error (30x should be handled since we set followredirect)

{

conn.disconnect();

if (status == 503) // we sent too many requests in too little time

{

try

{

System.err.println("Got 503 response to AXL request, sleeping for 10 seconds before retrying.");

Thread.sleep(10000); // sleep for ten seconds, then try again

return sendRequest(axlRequest, axlParams, utf8);

}

catch (InterruptedException ex)

{

throw new CommunicationException("Error executing POST Request. Status: " + status + " error: " + conn.getResponseMessage());

}

}

else

throw new CommunicationException("Error executing POST Request. Status: " + status + " error: " + conn.getResponseMessage());

}

String response = readServerResponse(conn.getInputStream(), true);

return processResponse(response, sAXLRequest);

}

catch (MalformedURLException m)

{

throw new CommunicationException("Malformed url: " + this.apiPath + "\r\nOriginal message: " + m.getMessage());

}

catch (IOException i)

{

throw new CommunicationException("IO problem: " + i.getMessage());

}

}

And here's the second method (had to remove it due to the post length limit this board has).

protected String generateAXLRequest(String request, String parameters)

{

StringBuilder soaprequest = new StringBuilder("http://schemas.xmlsoap.org/soap/envelope/\" ");

soaprequest.append("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"> ");

soaprequest.append(" <>http://www.cisco.com/AXL/1.0\" ");

soaprequest.append(" xsi:schemaLocation=\"http://www.cisco.com/AXL/1.0 http://ccmserver/schema/axlsoap.xsd\" ");

soaprequest.append("sequence=\"1234\"> " + parameters);

soaprequest.append(" ");

//tracer.Trace("AXL Request: " + request + "Parameters:\r\n" + parameters, 5);

return soaprequest.toString();

}

Stephen,

Problem solved. I did get the response back from the CUCM finally. :-)

I have also notinced one strange behavior, sometimes it gives 401 error and when I click the SEND REQUeST button for several times (avg 5 times) it displays the content [with the same userid and passcode], I wonder why??

And how do I send multiple SQL statements in one SOAP Request? And do you have any idea regarding the SQL on CUCM or where can I get documents on SQL on CUCM?

I really appreciate your help and effrots.

Thanks.

:-)

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: