Exchange Web Services
If you were at mine and Marshall's session at TechEd (or even Albert's session). You probably saw a demo of Speech Server accessing an Exchange Calendar using Speech Server.
Yes, Exchange 2007 does have a Voice Access feature as part of thier UM offering, but it's only configurable, you don't have too many choices on how the VUI actually works. Let's face it, just becuase a solution is good for one person doesn't make it right for you as every business is different!
So let's look at how we can access the Exchange Web Services.(At least the user availability tuffs) First you need need to add a reference to the Exchange Web Service.The path to your Web Service will be: http://<ExchangeServerName>/ews/exchange.asmx
If you are using Visual Studio, adding a web reference will automatically create a proxy for you! I wish everything was this simple.
First I want to create a simple object model to hold some of this data:
public class CalendarObject
{
private string _location;
private string _subject;
private bool _isMeeting;
private DateTime _startDate;
private DateTime _endDate;
public CalendarObject()
{
}
public string Location
{
get
{
return _location;
}
set
{
_location = value;
}
}
public string Subject
{
get
{
return _subject;
}
set
{
_subject = value;
}
}
public bool IsMeeting
{
get
{
return _isMeeting;
}
set
{
_isMeeting = value;
}
}
public DateTime StartDate
{
get
{
return _startDate;
}
set
{
_startDate = value;
}
}
public DateTime EndDate
{
get
{
return _endDate;
}
set
{
_endDate = value;
}
}
}
}
Ok now I actually need to retrieve data from the web service.
class ExchangeCalendar
{
//Force Static Method
private ExchangeCalendar()
{
}
public static List<CalendarObject> GetCalendarData(DateTime lookupDate)
{
List<CalendarObject> calendarObjects = new List<CalendarObject>();
ExchangeServiceBinding exchangeServer = new ExchangeServiceBinding();
ICredentials creds = new NetworkCredential("users", "password", "domain.com");
exchangeServer.Credentials = creds;
exchangeServer.Url = @"http://umdemo.dnsalias.com/ews/exchange.asmx";
GetUserAvailabilityRequestType request = new GetUserAvailabilityRequestType();
MailboxData[] mailboxes = new MailboxData[1];
mailboxes[0] = new MailboxData();
// Identify the user mailbox to review their Free/Busy data
EmailAddress emailAddress = new EmailAddress();
//User wer are getting status for, hardcoded here, but you could create a grammar item
// and pass it in.
emailAddress.Address = "user@domain.com";
emailAddress.Name = String.Empty;
mailboxes[0].Email = emailAddress;
request.MailboxDataArray = mailboxes;
//Set TimeZone
request.TimeZone = new SerializableTimeZone();
request.TimeZone.Bias = 480;
request.TimeZone.StandardTime = new SerializableTimeZoneTime();
request.TimeZone.StandardTime.Bias = 0;
request.TimeZone.StandardTime.DayOfWeek = DayOfWeekType.Sunday.ToString();
request.TimeZone.StandardTime.DayOrder = 1;
request.TimeZone.StandardTime.Month = 11;
request.TimeZone.StandardTime.Time = "02:00:00";
request.TimeZone.DaylightTime = new SerializableTimeZoneTime();
request.TimeZone.DaylightTime.Bias = -60;
request.TimeZone.DaylightTime.DayOfWeek = DayOfWeekType.Sunday.ToString();
request.TimeZone.DaylightTime.DayOrder = 2;
request.TimeZone.DaylightTime.Month = 3;
request.TimeZone.DaylightTime.Time = "02:00:00";
// Identify the time to compare if the user is Free/Busy
Duration duration = new Duration();
duration.StartTime = lookupDate;
duration.EndTime = lookupDate.AddDays(1);
// Identify the options for comparing F/B
FreeBusyViewOptionsType viewOptions = new FreeBusyViewOptionsType();
viewOptions.TimeWindow = duration;
viewOptions.RequestedView = FreeBusyViewType.Detailed;
viewOptions.RequestedViewSpecified = true;
request.FreeBusyViewOptions = viewOptions;
GetUserAvailabilityResponseType response = exchangeServer.GetUserAvailability(request);
foreach (FreeBusyResponseType responseType in response.FreeBusyResponseArray)
{
if (responseType.FreeBusyView.CalendarEventArray.Length > 0)
{
foreach (CalendarEvent calendar in responseType.FreeBusyView.CalendarEventArray)
{
CalendarObject calendarObject = new CalendarObject();
calendarObject.Location = calendar.CalendarEventDetails.Location;
calendarObject.Subject = calendar.CalendarEventDetails.Subject;
calendarObject.StartDate = calendar.StartTime;
calendarObject.EndDate = calendar.EndTime;
calendarObject.IsMeeting = calendar.CalendarEventDetails.IsMeeting;
calendarObjects.Add(calendarObject);
}
}
}
return calendarObjects;
}
}
I return a generic list so that we can easily databind this to a NavigableList activity. Which would allow the user to navigate through every object. See some of my previous post about actually doing the databinding. If you really really need to code to do it, send me a message.