Exchange WebService - Errorcode ErrorIncorrectUpdatePropertyCount при обновлении контакта - PullRequest
1 голос
/ 23 марта 2012

Я использую следующий метод для обновления контакта в Exchange через EWS:

    private void UpdateContact(Microsoft.Exchange.WebServices.Data.Contact exContact, ContactInfo contact) {
        var pathList = new List<string>();
        try {
            log.DebugFormat("Process ExchangeContact '{0}' with Contact '{1}'", (exContact.IsNew ? "<new>" : exContact.DisplayName), contact.Id);

            exContact.GivenName = contact.AdditionalName;
            exContact.Surname = contact.Name;
            exContact.FileAsMapping = FileAsMapping.SurnameCommaGivenName;

            exContact.CompanyName = "";
            if (contact is PersonInfo) {
                var person = (PersonInfo) contact;
                if (person.PersonCompany != null && person.PersonCompany.Company != null) {
                    exContact.CompanyName = person.PersonCompany.Company.DisplayName;
                }
                exContact.ImAddresses[ImAddressKey.ImAddress1] = person.MessengerName;
                exContact.ImAddresses[ImAddressKey.ImAddress2] = person.SkypeName;
            }

            // Specify the business, home, and car phone numbers.
            var comm = contact.GetCommunication(Constants.CommunicationType.PhoneBusiness);
            exContact.PhoneNumbers[PhoneNumberKey.BusinessPhone] = (comm != null ? comm.Value : null);
            comm = contact.GetCommunication(Constants.CommunicationType.PhonePrivate);
            exContact.PhoneNumbers[PhoneNumberKey.HomePhone] = (comm != null ? comm.Value : null);
            comm = contact.GetCommunication(Constants.CommunicationType.PhoneMobile);
            exContact.PhoneNumbers[PhoneNumberKey.MobilePhone] = (comm != null ? comm.Value : null);

            comm = contact.GetCommunication(Constants.CommunicationType.MailBusiness);
            exContact.EmailAddresses[EmailAddressKey.EmailAddress1] = (comm != null ? new EmailAddress(comm.Value) : null);
            comm = contact.GetCommunication(Constants.CommunicationType.MailPrivate);
            exContact.EmailAddresses[EmailAddressKey.EmailAddress2] = (comm != null ? new EmailAddress(comm.Value) : null);

            // Specify two IM addresses.

            // Specify the home address.
            var address = contact.AddressList.FirstOrDefault(x => x.AddressType != null && x.AddressType.Id == Constants.AddressType.Private);
            if (address != null) {
                var paEntry = new PhysicalAddressEntry
                    {
                        Street = address.Street,
                        City = address.City,
                        State = address.Region,
                        PostalCode = address.PostalCode,
                        CountryOrRegion = address.CountryName
                    };
                exContact.PhysicalAddresses[PhysicalAddressKey.Home] = paEntry;
                if (contact.PostalAddress == address) {
                    exContact.PostalAddressIndex = PhysicalAddressIndex.Home;
                }
            } else {
                exContact.PhysicalAddresses[PhysicalAddressKey.Home] = null;
            }
            address = contact.AddressList.FirstOrDefault(x => x.AddressType != null && x.AddressType.Id == Constants.AddressType.Business);
            if (address != null) {
                var paEntry = new PhysicalAddressEntry
                    {
                        Street = address.Street,
                        City = address.City,
                        State = address.Region,
                        PostalCode = address.PostalCode,
                        CountryOrRegion = address.CountryName
                    };

                exContact.PhysicalAddresses[PhysicalAddressKey.Business] = paEntry;
                if(contact.PostalAddress == address) {
                    exContact.PostalAddressIndex = PhysicalAddressIndex.Business;
                }
            } else {
                exContact.PhysicalAddresses[PhysicalAddressKey.Business] = null;
            }

            // Save the contact.
            if (exContact.IsNew) {
                exContact.Save();
            } else {
                exContact.Update(ConflictResolutionMode.AlwaysOverwrite);
            }

            pathList.AddRange(this.AddFileAttachments(this.Access.IndependService.GetContact(exContact.Id.UniqueId), contact.GetDocuments()));
        } catch(Exception e) {
            log.Error("Error updating/inserting Contact in Exchange.", e);
        } finally {
            foreach (var path in pathList) {
                this.Access.Context.Container.Resolve<IDocumentService>().UndoCheckOut(path);
            }
        }
    }

Когда я делаю это для обновления, я получаю исключение с кодом ошибки ErrorIncorrectUpdatePropertyCount в строке exContact.Update(ConflictResolutionMode.AlwaysOverwrite);

Может кто-нибудь мне помочь, в чем проблема?- Спасибо.

1 Ответ

1 голос
/ 27 марта 2012

Решение состоит в том, что я должен проверить, являются ли строковые значения пустыми строками и в этом случае установить нулевое значениеНа этом пути все работает.

...