Welcome...
-
Upload
martena-barker -
Category
Documents
-
view
18 -
download
1
description
Transcript of Welcome...
1
Welcome...
infosys
...to a talk about The Exchange Web Services Managed API
Code Camp Wellington 2009
Adrian (Bert) Garrett-TuckInfosys Limited
2
What we will cover
infosys
Welcome to Code Camp 2009!
• What is the Managed API?• The Exchange 2007 Web
Service• Interaction with the web
service via auto-gen’d proxy classes
• What is the EWS Managed API?• Why is it so much better?• Links and resources
3
The Exchange 2007 Web Service
infosys
• .NET 2.0 styles, SOAP web service.
• Is “the new guy” for Exchange 2007 interop
• Replaces WebDAV and CDOEX • Interact with it via VS
generated proxy classes. • Who’s done some work with it?
4
Interaction with the web service via auto-gen’d proxy classes
infosys
• Set up a binding• Create a request• Set request options (such as
folder, a view, whatever...• Set properties• Call the service & get a
response• Parse response
5
Interaction with the web service via auto-gen’d proxy classes
infosys
• Example 1 – Get inbox folder
GetFolderType request = new GetFolderType();
request.FolderShape = new FolderResponseShapeType();request.FolderShape.BaseShape =
DefaultShapeNamesType.AllProperties;
DistinguishedFolderIdType inboxId = new DistinguishedFolderIdType();
inboxId.Id = DistinguishedFolderIdNameType.inbox;
request.FolderIds = new BaseFolderIdType[] { inboxId };
GetFolderResponseType response = serviceBinding.GetFolder(request);
FolderInfoResponseMessageType responseMessage =response.ResponseMessages.Items[0] as
FolderInfoResponseMessageType;
if (responseMessage.ResponseClass == ResponseClassType.Success)
{ FolderType inbox = responseMessage.Folders[0] as
FolderType;}
6
Interaction with the web service via auto-gen’d proxy classes
infosys
• Example 2 – Find a folder called ‘Timesheet’
// Create the request and specify the traversal type.FindFolderType findFolderRequest = new FindFolderType();findFolderRequest.Traversal = FolderQueryTraversalType.Deep;
// Define the properties that are returned in the response.FolderResponseShapeType responseShape = new FolderResponseShapeType();responseShape.BaseShape = DefaultShapeNamesType.Default;findFolderRequest.FolderShape = responseShape;
// Identify which folders to search.DistinguishedFolderIdType[] folderIDArray = new DistinguishedFolderIdType[1];folderIDArray[0] = new DistinguishedFolderIdType();folderIDArray[0].Id = DistinguishedFolderIdNameType.msgfolderroot;
// Add the folders to search to the request.findFolderRequest.ParentFolderIds = folderIDArray;
// Send the request and get the response.FindFolderResponseType findFolderResponse = _binding.FindFolder(findFolderRequest);
if (findFolderResponse.ResponseMessages.Items[0].ResponseClass != ResponseClassType.Success){
throw new Exception(String.Format("Error:\r\n{0}\r\n{1}", findFolderResponse.ResponseMessages.Items[0].ResponseCode, findFolderResponse.ResponseMessages.Items[0].MessageText));
}
CalendarFolderType timesheetCalendarFolder = null;
foreach (BaseFolderType folder in ((FindFolderResponseMessageType)findFolderResponse.ResponseMessages.Items[0]).RootFolder.Folders){
if (folder is CalendarFolderType){
if (folder.DisplayName.ToLower() == "timesheet"){
timesheetCalendarFolder = (CalendarFolderType) folder;}
}}
if (timesheetCalendarFolder == null)return false;
// Form the FindItem request.FindItemType findItemRequest = new FindItemType();findItemRequest.ParentFolderIds = new[] {new FolderIdType()};findItemRequest.Traversal = ItemQueryTraversalType.Shallow;((FolderIdType) findItemRequest.ParentFolderIds[0]).Id =
timesheetCalendarFolder.FolderId.Id;findItemRequest.Item = _calendarView;
ItemResponseShapeType itemShapeDefinition = new ItemResponseShapeType();// Only need to retrieve the ItemId's in the find procedure...itemShapeDefinition.BaseShape = DefaultShapeNamesType.IdOnly;findItemRequest.ItemShape = itemShapeDefinition;
// Do the EWS Call...FindItemResponseType findItemResponse = _binding.FindItem(findItemRequest);// Check for errorsif (findItemResponse.ResponseMessages.Items[0].ResponseClass != ResponseClassType.Success){
throw new Exception(String.Format("Error:\r\n{0}\r\n{1}", findItemResponse.ResponseMessages.Items[0].ResponseCode, findItemResponse.ResponseMessages.Items[0].MessageText));
}
_findItemResponseMessage =(FindItemResponseMessageType) findItemResponse.ResponseMessages.Items[0];
_findCalled = true;return true;
70 Lines of Code to find a timesheet folder!
Another 30 lines to get some items out
7
What is the Managed API?
infosys
• Easier .NET Interop with Exchange 2007SP1 / 2010
• An additional assembly to reference
• Wraps up calls to the Exchange Web Service into simple methods.
• Significantly easier to use and manage than calling the web service via auto gen’d proxy directly
• 1.0 Beta • Will support all new features of
EWS as they become available.
8
Why is it so much better?
infosys
• Example 1
Folder inbox = Folder.Bind(service, WellKnownFolderName.Inbox);
• Example 2
Folder cal = Folder.Bind(service, WellKnownFolderName.Calendar); FolderView view = new FolderView(100);view.Traversal = FolderTraversal.Deep;view.PropertySet = new PropertySet(BasePropertySet.IdOnly);view.PropertySet.Add(FolderSchema.DisplayName);view.SearchFilter = new SearchFilter.ContainsSubstring(FolderSchema.DisplayName, "timesheet");FindFoldersResults result = service.FindFolders(cal.Id, view);Folder timesheetfolder = result[0];
9
Why it’s so much better!
infosys
• Saves a LOT of code!• Code is a lot more readable• Code is a lot more manageable
• Uses/wraps the Exchange 2007 Web Service – EWS here to stay
• Previously written web service proxy interop is not lost in vain
• Do upgrade when opportunity arises
Thanks and See Ya!
infosys
• Cheers for listening
Get slides fromhttp://www.infosys.co.nz
Links:• http://msdn.microsoft.com/en-u
s/library/dd633709.aspx
• http://blogs.msdn.com/mstehle/ (Matt Stehle, Exchange Team)