1 / 10

Welcome...

...to a talk about The Exchange Web Services Managed API Code Camp Wellington 2009 Adrian (Bert) Garrett-Tuck Infosys Limited. Welcome. i nfosys. Welcome to Code Camp 2009! What is the Managed API? The Exchange 2007 Web Service

Download Presentation

Welcome...

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. 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 What we will cover infosys

  3. .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? The Exchange 2007 Web Service infosys

  4. 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 Interaction with the web service via auto-gen’d proxy classes infosys

  5. Example 1 – Get inbox folder GetFolderType request = new GetFolderType(); request.FolderShape = new FolderResponseShapeType(); request.FolderShape.BaseShape = DefaultShapeNamesType.AllProperties; DistinguishedFolderIdTypeinboxId = new DistinguishedFolderIdType(); inboxId.Id = DistinguishedFolderIdNameType.inbox; request.FolderIds = new BaseFolderIdType[] { inboxId }; GetFolderResponseType response = serviceBinding.GetFolder(request); FolderInfoResponseMessageTyperesponseMessage = response.ResponseMessages.Items[0] as FolderInfoResponseMessageType; if (responseMessage.ResponseClass == ResponseClassType.Success) { FolderType inbox = responseMessage.Folders[0] as FolderType; } Interaction with the web service via auto-gen’d proxy classes infosys

  6. Example 2 – Find a folder called ‘Timesheet’ // Create the request and specify the traversal type. FindFolderTypefindFolderRequest = new FindFolderType(); findFolderRequest.Traversal = FolderQueryTraversalType.Deep; // Define the properties that are returned in the response. FolderResponseShapeTyperesponseShape = 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. FindFolderResponseTypefindFolderResponse = _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)); } CalendarFolderTypetimesheetCalendarFolder = 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. FindItemTypefindItemRequest = new FindItemType(); findItemRequest.ParentFolderIds = new[] {new FolderIdType()}; findItemRequest.Traversal = ItemQueryTraversalType.Shallow; ((FolderIdType) findItemRequest.ParentFolderIds[0]).Id = timesheetCalendarFolder.FolderId.Id; findItemRequest.Item = _calendarView; ItemResponseShapeTypeitemShapeDefinition = new ItemResponseShapeType(); // Only need to retrieve the ItemId's in the find procedure... itemShapeDefinition.BaseShape = DefaultShapeNamesType.IdOnly; findItemRequest.ItemShape = itemShapeDefinition; // Do the EWS Call... FindItemResponseTypefindItemResponse = _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; Interaction with the web service via auto-gen’d proxy classes 70 Lines of Code to find a timesheet folder! Another 30 lines to get some items out 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’dproxy directly • 1.0 Beta • Will support all new features of EWS as they become available. What is the Managed API? 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]; Why is it so much better? infosys

  9. 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 Why it’s so much better! infosys

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

More Related