Presentation is loading. Please wait.

Presentation is loading. Please wait.

Welcome... infosys...to a talk about The Exchange Web Services Managed API Code Camp Wellington 2009 Adrian (Bert) Garrett-Tuck Infosys Limited 1.

Similar presentations


Presentation on theme: "Welcome... infosys...to a talk about The Exchange Web Services Managed API Code Camp Wellington 2009 Adrian (Bert) Garrett-Tuck Infosys Limited 1."— Presentation transcript:

1 Welcome... infosys...to a talk about The Exchange Web Services Managed API Code Camp Wellington 2009 Adrian (Bert) Garrett-Tuck Infosys Limited 1

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 2

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? 3

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 4

5 Interaction with the web service via auto-gen’d proxy classes infosys Example 1 – Get inbox folder 5 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’ 6 // 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 errors if (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 7 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 8 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 9

10 Thanks and See Ya! infosys Cheers for listening Get slides from http://www.infosys.co.nz Links: http://msdn.microsoft.com/en- us/library/dd633709.aspxhttp://msdn.microsoft.com/en- us/library/dd633709.aspx http://blogs.msdn.com/mstehle/ (Matt Stehle, Exchange Team)http://blogs.msdn.com/mstehle/


Download ppt "Welcome... infosys...to a talk about The Exchange Web Services Managed API Code Camp Wellington 2009 Adrian (Bert) Garrett-Tuck Infosys Limited 1."

Similar presentations


Ads by Google