interacting with the exchange web services
TRANSCRIPT
www.orbitone.com
Raas van Gaverestraat 83B-9000 GENT, BelgiumE-mail [email protected] www.orbitone.com
Tel. +32 9 265 74 20Fax +32 9 265 74 10VAT BE 456.457.353Bank 442-7059001-50 (KBC)
9 October, 2008 Interacting with the Exchange Web Services, by Wim De Coninck
Exchange Web Services Architecture
9 October, 2008
Interacting with the Exchange Web Services,by Wim De Coninck2
Exchange Web Service: What can we do with it?
Interacting with the Exchange Web Services,by Wim De Coninck
9 October, 2008
• Autodiscover
• Calendaring
• Contact
• Folder
• Server Management
• Messaging
• MIME
• Security
• Store Event Sinks
• Store Schemas
• Store
• Synchronization
• Task Item
• Utility
• Notification
• Web services
3
Creating a basic contact
4 Interacting with the Exchange Web Services,by Wim De Coninck
9 October, 2008
Instantiate a ContactItemType
Set some properties on the contact
Specify the folder where you want the contact
Instantiate a CreateItemType
Add the contact to the createItem
Invoke the CreateItem method onthe webservice.
Process the response of the CreateItem method.
Zooming in...
To set email address on a contact, create a new List of EmailAddressDictionaryEntryType and add the email address to the array, then add the array to the contact’s email addresses property…
var contact = new ContactItemType();
var emails = new List<EmailAddressDictionaryEntryType>
{
new EmailAddressDictionaryEntryType
{
Key = EmailAddressKeyType.EmailAddress1,
Value = "[email protected]"
},
new EmailAddressDictionaryEntryType
{
Key = EmailAddressKeyType.EmailAddress1,
Value = "[email protected]"
}
};
contact.EmailAddresses = emails.ToArray();
Imagine doing this pre Framework 3.5
9 October, 2008
Interacting with the Exchange Web Services,by Wim De Coninck5
An extended property is a property that can beset on an item but which is not presentedthrough the webservice out of the box. For instance the gender of a contact.
In this case we would create a new Extendedproperty. The ExtendedFieldURI of thatproperty is a path to extended field type whichmaps to a property that is visible in outlook. The item will contain the value that is to bedisplayed in the specified field.
ExtendedPropertyType gender =
new ExtendedPropertyType();
gender.ExtendedFieldURI =
new PathToExtendedFieldType();
gender.ExtendedFieldURI.PropertyTag = "0x3a4d";
gender.ExtendedFieldURI.PropertyType =
MapiPropertyTypeType.Short;
gender.Item = ((int)pGender).ToString();
Extended Properties
Interacting with the Exchange Web Services,by Wim De Coninck
9 October, 20086
7 Interacting with the Exchange Web Services,by Wim De Coninck
9 October, 2008
Distribution List
You can’t create a distribution list. The CreateItem web method does not allow you to add a DistributionList.
How do we work around that ?
Create an itemtype and addextended properties ‘till itbecomes a distributionlist, and set the ItemClass to IPM.DistList
9 October, 2008
Interacting with the Exchange Web Services,by Wim De Coninck8
Adding the members
WARNING:
2 Extended properties:
Member
OneOffMember
Both expect a BinaryArray.
They are limited to 15000 bytes, (about 140 contact entries)
Foreach entry in member there must be an entry in oneOffMember at the same index.
BinaryArray equals Base64String[]
9 October, 2008
Interacting with the Exchange Web Services,by Wim De Coninck9
Member
A member contains a link to contact through a hexed entry id.
What we have is the ItemId and the ConvertId web method.
ConvertIdType convertReq = new ConvertIdType();
convertReq.DestinationFormat = IdFormatType.HexEntryId;
convertReq.SourceIds = new[]
{
new AlternateIdType()
{
Format = IdFormatType.EntryId,
Mailbox = "[email protected]",
Id = item.ItemId.Id
}
};
ConvertIdResponseType response = esb.ConvertId(convertReq);
9 October, 2008
Interacting with the Exchange Web Services,by Wim De Coninck10
Member: the actual base 64 string
The wrapped entry id is what we want in the base 64 string.
Prefix of wrapped entry id = 00000000C091ADD3519DCF11A4A900AA0047FAA4C3 00000000
The response contains a string with bytes.
We only need part a of the retreived string.0003240033636237313064392D323134342D343761632D626137612D393730646364656335343
664004600000000002F6E0D571298F14DA8E47B5FEDAA78A507001DD4ACE8303DD54F87DD53DA592670810001F3D7468A00000988B48B0E4D054284347C283576FD020424930B44BC0000
9 October, 2008
Interacting with the Exchange Web Services,by Wim De Coninck11
OneOffMember
12 Interacting with the Exchange Web Services,by Wim De Coninck
9 October, 2008
var retval = new List<byte>();
var flags = Encoding.Unicode.GetBytes("\0\0");
var version = Encoding.Unicode.GetBytes("\0");
var pad = Encoding.Unicode.GetBytes("\0");
var muid = new byte[]
{
0x81, 0x2b, 0x1f, 0xa4, 0xbe,
0xa3, 0x10, 0x19, 0x9d, 0x6e,
0x00, 0xdd, 0x01, 0x0f, 0x54, 0x02
};
var wFlags = new byte[] { 0x01, 0x90 };
var first =
Encoding.Unicode.GetBytes(“contactname([email protected])”);
var middle = Encoding.Unicode.GetBytes("UNKNOWN");
var last = Encoding.Unicode.GetBytes(“[email protected]”);
retval.AddRange(flags);
retval.AddRange(muid);
retval.AddRange(version);
retval.AddRange(wFlags);
retval.AddRange(first);
retval.AddRange(pad);
retval.AddRange(middle);
retval.AddRange(pad);
retval.AddRange(last);
retval.AddRange(pad);
Resources
http://msdn.microsoft.com/en-us/library/bb408417.aspx
9 October, 2008
Interacting with the Exchange Web Services,by Wim De Coninck13
www.orbitone.com
14 Interacting with the Exchange Web Services,by Wim De Coninck
9 October, 2008