Trouble updating contacts’ physical addresses using EWS Managed API?
This happened to be a second recent case among many others facing the similar issue, and they could not update an existing contact using EWS Managed API.
I got this customer, like all others complaining that they cannot set the contact’s Physical Address to a blank value. The same contact can be updated using EWS SOAP API but not with managed API… hmm… I knew the answer already
Error Message: The request failed schema validation: The element 'Updates' in namespace ' https://schemas.microsoft.com/exchange/services/2006/types' has incomplete content. List of possible elements expected: 'AppendToItemField, SetItemField, DeleteItemField' in namespace 'https://schemas.microsoft.com/exchange/services/2006/types'.
Here is the code which was causing the trouble
static void UpdateContact(ExchangeService svc,ItemId id)
{
Contact myContact = Contact.Bind(svc, id);
PhysicalAddressEntry paEntryHome = null;
PhysicalAddressEntry paEntryBusiness = null;
paEntryHome = new PhysicalAddressEntry();
paEntryHome.Street = "";
paEntryHome.City = "";
paEntryHome.PostalCode = "";
paEntryHome.State = "";
paEntryHome.CountryOrRegion = "";
paEntryBusiness = new PhysicalAddressEntry();
paEntryBusiness.Street = "";
paEntryBusiness.City = "";
paEntryBusiness.PostalCode = "";
paEntryBusiness.State = "";
paEntryBusiness.CountryOrRegion = "";
myContact.PhysicalAddresses[PhysicalAddressKey.Home] = paEntryHome;
myContact.PhysicalAddresses[PhysicalAddressKey.Business] = paEntryBusiness;
try
{
myContact.Update(ConflictResolutionMode.AlwaysOverwrite);
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
}
}
So what was the trouble in the code, it look pretty neat.. huh? Not exactly. You are creating a new instance of PhysicalAddressEntry instead of using the existing object given by Managed API..
Only, few lines of code change and it started to work like charm.. here is the working code for the same.
static void UpdateContact(ExchangeService svc,ItemId id)
{
Contact myContact = Contact.Bind(svc, id);
PhysicalAddressEntry paEntryHome = null;
PhysicalAddressEntry paEntryBusiness = null;
paEntryHome = myContact.PhysicalAddresses[PhysicalAddressKey.Home];
paEntryBusiness = myContact.PhysicalAddresses[PhysicalAddressKey.Business];
paEntryHome.Street = "";
paEntryHome.City = "";
paEntryHome.PostalCode = "";
paEntryHome.State = "";
paEntryHome.CountryOrRegion = "";
paEntryBusiness.Street = "";
paEntryBusiness.City = "";
paEntryBusiness.PostalCode = "";
paEntryBusiness.State = "";
paEntryBusiness.CountryOrRegion = "";
try
{
myContact.Update(ConflictResolutionMode.AlwaysOverwrite);
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
}
}
Hope this helps you all.
Happy coding / debugging!!!
Comments
- Anonymous
July 12, 2011
And why shouldn't the first one work? Lazy API implementation?