Inside Microsoft® Exchange Server 2007 Web Servicesby David Sterling; Ben Spain; Michael Mainer; MarkTaylor; Huw Upshall Publisher: Microsoft Press Pub Date: November 28, 2007 Print ISBN
Trang 1Inside Microsoft® Exchange Server 2007 Web Services
by David Sterling; Ben Spain; Michael Mainer; MarkTaylor; Huw Upshall
Publisher: Microsoft Press Pub Date: November 28, 2007 Print ISBN-10: 0-7356-2392-9 Print ISBN-13: 978-0-7356-2392-7 Pages: 928
Table of Contents | Index
Overview
Dive deep into the architecture of Exchange Web Servicesandmaster the intricacies for accessing data with the new, unifyingAPI Exchange Web Services offers new functionality, replacingold, disparate APIs This practical guide introduces developers
to Exchange Web Services It includes comprehensive, in-depthcoverage of the architecture and key features, including
messaging, folders, calendaring, tasks, notifications, searching,availability, and autodiscovery Developers who are movingapplications using previous APIs to Exchange Web Services willlearn how to determine the correct web services constructsandthe implications of those decisions This book assumes onlyknowledge of how to write HTTP requests, but it provides proxyexamples in Microsoft Visual C#
Trang 2Inside Microsoft® Exchange Server 2007 Web Services
by David Sterling; Ben Spain; Michael Mainer; MarkTaylor; Huw Upshall
Publisher: Microsoft Press
Pub Date: November 28, 2007
Print ISBN-10: 0-7356-2392-9 Print ISBN-13: 978-0-7356-2392-7 Pages: 928
Trang 5Search Folders and the FindItem OperationsThe FindItem/SearchFolder Balancing Act
Trang 6Exchange Web Services Search Folder QuirksSummary
Trang 8More Great Developer Resources from Microsoft PressDeveloper Step by Step
Developer Reference
Focused Topics
Index
Trang 9distributors worldwide For further information about
international editions, contact your local Microsoft Corporationoffice or contact Microsoft Press International directly at fax(425) 936-7329 Visit our Web site at
www.microsoft.com/mspress Send comments to
mspinput@microsoft.com
Microsoft, Microsoft Press, Active Directory, ActiveSync, ActiveX,Expression, Front Page, IntelliSense, Internet Explorer, MSDN,Outlook, Visual Studio, Win32, Windows, Windows NT, and
Windows PowerShell are either registered trademarks or
trademarks of Microsoft Corporation in the United States and/orother countries Other product and company names mentioned
Trang 10The example companies, organizations, products, domain
names, e-mail addresses, logos, people, places, and eventsdepicted herein are fictitious No association with any real
company, organization, product, domain name, e-mail address,logo, person, place, or event is intended or should be inferred.This book expresses the author's views and opinions The
information contained in this book is provided without any
express, statutory, or implied warranties Neither the authors,Microsoft Corporation, nor its resellers, or distributors will beheld liable for any damages caused or alleged to be causedeither directly or indirectly by this book
you.
—David
To Stacey: You convince me more and more each day that I have found the perfect partner in life Here is to our years past, and to many, many more To Isaiah: Daddy is very proud of you, and you have inspired me more then you will ever know Now, let's go find those race cars!
—Ben
Trang 11I dedicate this book to my parents, Manford and Karen Mainer, who gave me life and shared with me wisdom and love that I cherish to this day.
Trang 12To my fellow authors, thanks for all the time and effort you putinto writing the content for this book It was demanding andabove and beyond your normal workload at Microsoft You willnever look at a Word document with change tracking in the
same way again!
I want to thank my technical reviewers, Chris Simison and BobDean Chris, you did an excellent (and exceedingly thorough)job of reviewing this book You were a true advocate for thereader and this book is MUCH better as a result of your hardwork Thanks for taking on the project and sticking with it! Bob,thanks for coming onboard to keep the schedule from slipping.This book was indeed quite an undertaking, but more so wasthe Exchange Web Service software that this book is about Assuch, I want to thank the Exchange Web Services team for yourfriendship, teamwork, and the innovation that you poured intothe product (ordered by first name): Ben Spain, Bob Congdon,Chris Simison, David Claux, Gauri Deshpande, Henrik Jensen,Huw Upshall, Ilya Smirnov, James Shen, Jason Henderson, JohnGibbon, John Merrill, Kumarswamy Valegerepura, Mark Taylor,Michael Mainer, Rahul Dhar, Raz Mathias, Rebecca Zou, Rob
McCann, and Robin Thomas Karim Batthish, you have a vastamount of technical knowledge in your head—thanks for
Trang 13To the editing team, your kind attention to both the big andsmall details has made the end product much better than thedrafts I submitted: Victoria Thulman, Devon Musgrave, MeganSmith-Creed, Jan Clavey, and Sarah Wales McGrath Ben Ryan,thanks for looking at and taking the book proposal through theapproval process in the first place!
I want to thank all the people who reviewed early drafts of thechapters: Roosevelt Sheriff, Henrik Jensen, Kumarswamy
Valegerepura, John Gibbon, Wilson Li, Jaya Matthew, Ilya
Smirnov, David Claux, and Karim Batthish And lastly, I wouldlike to thank my keyboard and coffee maker for bearing withthe extra load during this time
From Ben
To my fellow authors, David, Mark, Michael, and Huw, this hasbeen a terrific ride To our technical reviewer, Chris, you trulywent the extra mile and I could not have made it sound like Iknew anything without your help
From Michael
First, I want to thank Martin Tracy for inspiring choices thateventually led me to this book Thank you, Martin Next, I want
to thank David Sterling for putting this book project together
He has valiantly led the development of this content He is such
authors, editor, technical reviewers, the people at MicrosoftPress, Microsoft Corporation, and any other person or
a valuable asset to any project I also want to thank my co-organization that has contributed to the creation of this book.Most importantly, I want to acknowledge the customer Withoutthe customers, without our partners, this book would be a
Trang 14From Mark
I would like to thank all those who reviewed my material,
including my fellow authors and other colleagues Your time anddiligence helped me improve my explanations and remove thosesilly mistakes
Trang 15One mid-year day in 2006, as the Exchange Web Services teamwas finishing work on Exchange 2007, David Sterling walkedinto Chris Simison's office and said, "You might think this is
crazy, but what would you think if I wrote a book on ExchangeWeb Services?"[1] Chris was his manager at the time and
mentioned that the thought was not actually crazy and that
several others had tossed the idea back and forth, but nothinghad been decided yet So began the story of this year-long
endeavor to take the information from the collective brain of theExchange Web Services team and put it in writing
[1] Chris Simison was the primary technical reviewer for this book.
The need for such a book was well established, being that
Exchange Web Services was a completely new application
programming interface (API) for Exchange The material thatneeded to be covered was certainly there, as can be seen bythe size of this book However, what we had not yet determined
was how to present the material and who the intended audience
would be You see, a Web Service by nature deals with SimpleObject Access Protocol (SOAP) XML messages, which can becreated and consumed on any operating system that knowshow to deal with text So the natural way to talk about a WebService API is to talk about the XML schema that defines thestructure of the request and response messages and to showexamples of compliant XML instance documents representingthose messages Such a presentation appeals to us since wespend so much time dealing with raw XML In addition, sinceSOAP messages represent the "native" way to communicatewith Web Services, such a presentation could be understood bythose developing on non-Microsoft platforms as there are noMicrosoft-specific constructs that get in the way
However, we also went with the assumption that many of ourreaders would be developing applications on the Microsoft
platform, and most of those would be using Visual Studio 2003
Trang 16Chapter 1, Visual Studio simplifies Web Service communication
by creating auto-generated proxy classes that deal with XMLgeneration and parsing under the covers However, the proxygenerator used by Visual Studio is not the only proxy generatoravailable In fact, with the advent of Windows CommunicationFoundation (WCF) in the Microsoft NET 3.0 framework,
Microsoft has released another utility (svcutil.exe) that
generates a different set of auto-generated proxy classes that
can be used to talk to a Web Service And of course, there areproxy generators for other platforms such as Axis for Java
Although talking about the XML message structure is convenientfor instruction, in practice most developers will be using auto-generated proxy classes to manage their communication with
Exchange Web Services But which set of proxy classes should
we use when writing this book? In the end, we decided that themost used proxy generator for talking with Exchange Web
Services would be the one used by Visual Studio 2003 or 2005.[2] As such, in addition to discussing the raw XML structure ofthe SOAP messages passed between a client application andExchange Web Services, we also include a number of examples
of how to program using the auto-generated proxy classes
[2] At least until the next version of Visual Studio is officially released.
So, the general pattern in the book is that we first present theconcept using XML and XML schema and then make that
concept more concrete by writing proxy class code to show theconcept at work
What Does This Book Cover?
This book is divided into five parts Each part contains chaptersthat are in some way related (very loosely in some cases) Theparts are as follows:
Part I : The Basics
Trang 17covered in Part III, Chapter 15) Part II covers Folders (Chapter
4), Items (Chapter 5), Contacts and Distribution Lists (Chapter
6), Messages (Chapter 7), Calendar related items (Chapter 8
through Chapter 10), Tasks (Chapter 11), and Attachments
(Chapter 12) Part II concludes with an indepth discussion ofaccessing native MAPI properties using Exchange Web Servicesextended properties, which is an important chapter since youwill see extended properties used throughout the book (Chapter
13)
Part III : Searching
Part III discusses the restriction architecture in Exchange WebServices Restrictions provide a way for Exchange Web Serviceconsumers to search for items or folders that meet a certain set
Trang 18functionality such as paging, grouping, and search folders arediscussed (Chapter 15)
Part IV : Keeping You in the Loop
Part IV covers the Exchange Web Service functionality used toalert you of changes to the content of a Mailbox The
Synchronization (Chapter 16) and Notification (Chapter 17)
chapters discuss the features of each and when you would
choose one over the other
Part V : Advanced Topics
The last section of the book covers various and sundry topicsthat defied categorization
Chapter 18 covers error handling in Exchange Web Services.Exchange Web Services is a batching API, and therefore errorsare reported in a slightly different fashion than you may be
used to In addition, you will encounter SOAP faults, which are
a by-product of communicating via SOAP messages
Chapter 19 discusses Server to Server (S2S) authentication,which allows properly configured accounts to perform work onbehalf of another account S2S authentication enables ExchangeWeb Services to be leveraged as part of a more elaborate workprocess without having to set up a complex single-sign-on
SetUserOofSettings allow you to retrieve and set (respectively)
Trang 19Who Is This Book For?
This book is primarily aimed at developers who will be writingapplications that use Exchange Web Services to talk to
Exchange Server 2007 We assume that the reader is
comfortable with the Microsoft NET 2.0 framework and the C#programming language For instance, many of the C# examples
in this book make use of partial class extensions and generics
In addition, we assume a basic familiarity with XML We do not,however, assume that the reader has had any exposure to
programming against Exchange using any other API
Companion Web Site
On the companion Web site, you'll find four tastefully appointedappendices that will prove useful in your Exchange Web Servicedevelopment experience
Appendix A "Response Codes," provides the error response
codes that are defined in the Exchange Web Services schema,what they mean, and what Web methods you may encounterthem from
Appendix B, "Calendaring Supplementals," provides additionalsource code to aid in calendaring development
Appendix C, "Mapping to MAPI Properties," talks about the
property paths exposed in Exchange Web Services, the MAPIproperties that each maps to (if applicable), and the operationsthat can be performed on each property
Appendix D, "SP1 Feature Review," offers a quick view of theExchange Web Service features that are expected to be
released in Exchange 2007 Service Pack 1 Note that this bookdoes not cover SP1 features
All the code samples discussed in this book can be downloadedfrom the book's companion Web page at the following address:
Trang 20System Requirements
To use Microsoft Exchange 2007 Web Services, you must haveaccess to an Exchange 2007 Client Access Server Several
chapters cover topics that require administrative privileges inExchange and the Active Directory However, in such cases, youcan simply follow along in the book if you do not have
mspinput@microsoft.com
Or via postal mail to
Trang 21Microsoft PressAttn: Inside Microsoft Exchange Server 2007 Web Services One Microsoft Way
Redmond, WA 98052-6399
Please note that Microsoft software product support is not
offered through the above addresses
Trang 22Welcome to Exchange Web ServicesMay I See Your Id?
Property Paths and Response Shapes
Trang 23Services
Believe it or not, this is the last chapter that we wrote for thebook We figured that it would be better to write all of the otherchapters first so as to know what to introduce rather than
introducing one thing and then writing about another.[1] Thebook that is before you is an exhaustive look at the MicrosoftExchange Server 2007 Web Services (EWS) application
programming interface (API) Throughout this book, we've tried
to give you an understanding of why the Exchange Web
Services development team did things the way they did Yousee, developing software is a process The consumer will
typically see the end product as if it magically popped out ofthin air But it didn't magically appear There were meetings,specs, coding sessions, coffee, code reviews, debugging
sessions, coffee, testing, explanations, eureka moments, coffee,and so on that constitute the API covered by this book The APIgrew out of these experiences—the experiences of the
developers, testers, program managers, documenters, and
other members that make up the Exchange Web Services team
It is our goal that you will not only understand how to program
on Exchange using Exchange Web Services, but also why theExchange Web Services team designed it the way they did
Trang 24contacts, and tasks What Exchange Web Services covers is thesubject of this book
What Features Are Missing?
The RTM version of Exchange Web Services offers a great deal
of functionality However, several significant areas are missing.Folder Associated Information (FAI) messages
Trang 25on these issues and more If you need such functionality, youwill have to continue using your legacy APIs until this
functionality is provided by Exchange Web Services We
encourage you to visit the TechNet forums and let the ExchangeWeb Services developers know which legacy features you want
to appear in Exchange Web Services The development forum islocated here:[2]
overlap in many places
Figure 1-1 Shipping APIs for Exchange
[View full size image]
Trang 26is a method to their madness Before Exchange Web Services,which API you talked to depended on your location (intranet orInternet), your development language of choice, your platform,and how much Outlook interoperability business logic you
wanted to implement yourself Refer to the grid in Figure 1-2
Figure 1-2 The API grid
Trang 27Prior to Exchange 2007, there was nothing in the lower right-API that could be called regardless of location and platform and
offer Outlook and Outlook Web Access interoperability, then
many of the disparate, partial APIs could be deprecated In fact,the end goal is to have a single API for accessing Exchange
mailbox data "What about Windows PowerShell and the EdgeExtensibility API?" you ask Windows PowerShell, which is
exposed in Exchange 2007 as the Exchange Management Shell,provides an excellent scripting environment for performing
administrative tasks However, it is not geared toward mailboxowner actions, such as sending meeting invitations The EdgeExtensibility API is geared toward developers who want to insertthemselves into the mail receiving and sending pipeline In theend, a single API for everything is unlikely However, the
overlap between APIs will be insignificant if not non-existent
How Do You Talk to Exchange Web Services?
Because Exchange Web Services is a SOAP-based Web service,all communication must be over HTTP with an XML body Thereare two primary ways to get there First, die-hard programmersmight indeed manually create XML and send it over HTTP
explicitly If you are using the NET Framework, you can use a
class such as HttpWebRequest to do this as shown in
Trang 28camera consumer, you do need the manual if you are going to
figure out how to set the date, turn off the flash, format thememory card, and so on
Now, this WSDL file is indeed a poor user's manual, but it is
Trang 29autogenerated proxies that most of you use when talking toExchange Web Services You see, the WSDL file is itself an XMLfile that lists all of the methods that can be called, the particularinput and output types, the protocols that are supported, andthings of that nature.[4] As a consumer, you point your proxygenerator of choice to the Services.wsdl file, and the proxy
generator magically creates numerous classes with methodsand properties that enable you to talk to Exchange Web
Exchange Web Services responds with SOAP+XML, which theproxy then takes and converts into your method response Ifyou consider Figure 1-3, the client box can actually contain
Trang 30method call on the proxy class, the resulting request is
being serialized, sent over the wire to the Exchange WebServices server, processed, sent back to the proxy, and thendeserialized into the response Make sure that you
understand the performance implications of such proxy callsduring your design phase
Trang 31Welcome to Exchange Web ServicesMay I See Your Id?
Property Paths and Response Shapes
Trang 32Services
Believe it or not, this is the last chapter that we wrote for thebook We figured that it would be better to write all of the otherchapters first so as to know what to introduce rather than
introducing one thing and then writing about another.[1] Thebook that is before you is an exhaustive look at the MicrosoftExchange Server 2007 Web Services (EWS) application
programming interface (API) Throughout this book, we've tried
to give you an understanding of why the Exchange Web
Services development team did things the way they did Yousee, developing software is a process The consumer will
typically see the end product as if it magically popped out ofthin air But it didn't magically appear There were meetings,specs, coding sessions, coffee, code reviews, debugging
sessions, coffee, testing, explanations, eureka moments, coffee,and so on that constitute the API covered by this book The APIgrew out of these experiences—the experiences of the
developers, testers, program managers, documenters, and
other members that make up the Exchange Web Services team
It is our goal that you will not only understand how to program
on Exchange using Exchange Web Services, but also why theExchange Web Services team designed it the way they did
Trang 33contacts, and tasks What Exchange Web Services covers is thesubject of this book
What Features Are Missing?
The RTM version of Exchange Web Services offers a great deal
of functionality However, several significant areas are missing.Folder Associated Information (FAI) messages
Trang 34on these issues and more If you need such functionality, youwill have to continue using your legacy APIs until this
functionality is provided by Exchange Web Services We
encourage you to visit the TechNet forums and let the ExchangeWeb Services developers know which legacy features you want
to appear in Exchange Web Services The development forum islocated here:[2]
overlap in many places
Figure 1-1 Shipping APIs for Exchange
[View full size image]
Trang 35is a method to their madness Before Exchange Web Services,which API you talked to depended on your location (intranet orInternet), your development language of choice, your platform,and how much Outlook interoperability business logic you
wanted to implement yourself Refer to the grid in Figure 1-2
Figure 1-2 The API grid
Trang 36Prior to Exchange 2007, there was nothing in the lower right-API that could be called regardless of location and platform and
offer Outlook and Outlook Web Access interoperability, then
many of the disparate, partial APIs could be deprecated In fact,the end goal is to have a single API for accessing Exchange
mailbox data "What about Windows PowerShell and the EdgeExtensibility API?" you ask Windows PowerShell, which is
exposed in Exchange 2007 as the Exchange Management Shell,provides an excellent scripting environment for performing
administrative tasks However, it is not geared toward mailboxowner actions, such as sending meeting invitations The EdgeExtensibility API is geared toward developers who want to insertthemselves into the mail receiving and sending pipeline In theend, a single API for everything is unlikely However, the
overlap between APIs will be insignificant if not non-existent
How Do You Talk to Exchange Web Services?
Because Exchange Web Services is a SOAP-based Web service,all communication must be over HTTP with an XML body Thereare two primary ways to get there First, die-hard programmersmight indeed manually create XML and send it over HTTP
explicitly If you are using the NET Framework, you can use a
class such as HttpWebRequest to do this as shown in
Trang 37camera consumer, you do need the manual if you are going to
figure out how to set the date, turn off the flash, format thememory card, and so on
Now, this WSDL file is indeed a poor user's manual, but it is
Trang 38autogenerated proxies that most of you use when talking toExchange Web Services You see, the WSDL file is itself an XMLfile that lists all of the methods that can be called, the particularinput and output types, the protocols that are supported, andthings of that nature.[4] As a consumer, you point your proxygenerator of choice to the Services.wsdl file, and the proxy
generator magically creates numerous classes with methodsand properties that enable you to talk to Exchange Web
Exchange Web Services responds with SOAP+XML, which theproxy then takes and converts into your method response Ifyou consider Figure 1-3, the client box can actually contain
Trang 39method call on the proxy class, the resulting request is
being serialized, sent over the wire to the Exchange WebServices server, processed, sent back to the proxy, and thendeserialized into the response Make sure that you
understand the performance implications of such proxy callsduring your design phase
Trang 40Welcome to Exchange Web ServicesMay I See Your Id?
Property Paths and Response Shapes