Below you will find a simple application to send a simple command via a CiscoIPPhoneText XML statement.
For more details on CISCOIPPhoneText and other XML commands see http://www.cisco.com/en/US/docs/voice_ip_comm/cuipph/all_models/xsi/6_0/english/programming/guide/XSIbook.html
Below is a screen shot of the output on a 7960 series phone
and the console application when running
HTTP Server Requests (HTTP POST)
The following description designates how an HTTP server request is made to the phone via an HTTP POST operation:
- The server performs an HTTP POST in response to a case-sensitive URL of the phone with this format: http://x.x.x.x/CGI/Execute, where x.x.x.x represents the IP address of the destination Cisco Unified IP Phone.
The form that is posted should have a case-sensitive form field name called "XML" that contains the desired XML object. For any HTTP POST operation, the server must provide basic HTTP authentication information with the POST. The provided credentials must be of a user in the global directory with a device association with the target phone.
If the credentials are invalid, or the Authentication URL is not set properly in the Cisco Unified Communications Manager Administration, the phone will return a CiscoIPPhoneError with a value of 4 (Authentication Error) and processing will stop. - The phone processes the supported HTTP headers
- The phone parses and validates the XML object
- The phone presents data and options to the user, or in the case of a CiscoIPPhoneExecute object, begins executing the URIs.
APP.CONFIG
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="CallManagerPushUsername" value="ccrowe-test"></add>
<add key="CallManagerPushPassword" value="123456"></add>
</appSettings>
</configuration>
Program.CS
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
using System.Web;
namespace TestApplication_SendSimpleMessageToPhone
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Send a simple XML Command to a CISCO IP Phone");
Console.WriteLine();
string IPAddressOfPhone = "10.3.21.228";
int HTTPServerTimeoutMS = 30000;
string PhoneURL = string.Format("http://{0}/CGI/Execute", IPAddressOfPhone);
string PushXML = "";
string ResponseXML = "";
string ErrorCode = "";
PushXML = @"<CiscoIPPhoneText>";
PushXML += @"<Title>Title Text Goes Here</Title>"; // Optional Field
PushXML += @"<Prompt>The prompt text goes here</Prompt>"; // Optional Field
PushXML += @"<Text>The text to be displayed as the message body</Text>";
PushXML += @"<SoftKeyItem>"; // Optional Field
PushXML += @"<Name>Cancel</Name>";
PushXML += @"<URL>SoftKey:Cancel</URL>";
PushXML += @"<Position>4</Position>";
PushXML += @"</SoftKeyItem>";
PushXML += @"</CiscoIPPhoneText>";
Console.WriteLine("Sending the following POST data:");
Console.WriteLine();
Console.WriteLine(PushXML);
Console.WriteLine();
PushXML = "XML=" + HttpUtility.UrlEncode(PushXML);
WebResponse resp = null;
try
{
ServicePointManager.Expect100Continue = false;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(PhoneURL);
req.Timeout = HTTPServerTimeoutMS;
req.Method = "POST";
req.Credentials = GetCredentials();
req.Accept = "*/*";
req.ContentType = "application/x-www-form-urlencoded";
req.KeepAlive = false;
req.Expect = "";
byte[] bytes = null;
bytes = System.Text.Encoding.UTF8.GetBytes(PushXML);
Stream outputStream = req.GetRequestStream();
outputStream.Write(bytes, 0, bytes.Length);
outputStream.Close();
resp = req.GetResponse();
Stream s = resp.GetResponseStream();
StreamReader stm = new StreamReader(s);
if (stm == null)
{
ErrorCode = "Timed out or no response!";
}
else
{
ResponseXML = stm.ReadToEnd();
stm.Close();
}
s.Close();
resp.Close();
}
catch (System.Net.WebException ex)
{
string StatusCodeString = ex.Response == null ? "" : (ex.Response as HttpWebResponse).StatusCode.ToString();
int StatusCodeNumber = ex.Response == null ? -1 : Convert.ToInt32((ex.Response as HttpWebResponse).StatusCode);
ErrorCode = string.Format("Web Exception : {0}\r\n\r\n" +
"HTTP Status : {1} ({2})\r\n\r\n" +
"Stack Trace:\r\n\r\n{3}",
ex.Message.ToString(),
StatusCodeString, StatusCodeNumber,
ex.ToString());
}
catch (Exception ex)
{
ErrorCode = string.Format("Exception : {0}\r\n\r\n" +
"Stack Trace:\r\n{1}",
ex.Message.ToString(),
ex.ToString());
}
if (ErrorCode.Length > 0)
Console.WriteLine(ErrorCode);
else
{
Console.WriteLine();
Console.WriteLine("Received the following XML response");
Console.WriteLine();
Console.WriteLine(ResponseXML);
}
Console.WriteLine();
Console.WriteLine("Completed... click ENTER to exit");
Console.ReadLine();
}
private static ICredentials GetCredentials()
{
string Username = System.Configuration.ConfigurationManager.AppSettings["CallManagerPushUsername"];
string Password = System.Configuration.ConfigurationManager.AppSettings["CallManagerPushPassword"];
return new NetworkCredential(Username, Password);
}
}
}