2012-03-23 3 views
1

ich die Brache Methode verwenden, um einen Kontakt in Exchange über EWS zu aktualisieren:Exchange-WebService - Fehlercode ErrorIncorrectUpdatePropertyCount wenn updateing Kontakt

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); 
      } 
     } 
    } 

Wenn ich dieses Update für tun, erhalte ich eine Ausnahme mit Fehlercode ErrorIncorrectUpdatePropertyCount auf der Linie exContact.Update(ConflictResolutionMode.AlwaysOverwrite);

Kann mir jemand helfen, was ist das Problem? - Vielen Dank.

Antwort

1

Die Lösung ist, dass ich überprüfen muss, ob die String-Werte leere Zeichenfolgen sind und in diesem Fall Null gesetzt werden. Auf diesem Weg funktioniert alles.