2012-11-19 24 views
4

我正在忙于编写一些代码,这些代码将通过PHPEWS更新Microsoft Exchange服务器上的物理地址;使用PHP EWS更新联系人物理地址

但是对于我的生活我无法完全弄清楚如何更新物理地址,我可以更新除此之外的所有其他内容。

这是我的代码。

// Update Physical Address. 
$field = new EWSType_SetItemFieldType(); 
$field->IndexedFieldURI->FieldURI = 'contacts:PhysicalAddress:Street'; 
$field->IndexedFieldURI->FieldIndex = EWSType_PhysicalAddressKeyType::HOME; 

$field->Contact = new EWSType_ContactItemType(); 
$field->Contact->PhysicalAddress = new EWSType_PhysicalAddressDictionaryType(); 

$address = new EWSType_PhysicalAddressDictionaryEntryType(); 
$address->Key = EWSType_PhysicalAddressKeyType::HOME; 
$address->_ = $street; 

$field->Contact->PhysicalAddresses->Entry = $address; 
$change->Updates->SetItemField[] = $field; 

我不断收到以下错误多小时的反复试验,我终于算出来后,我自己

Array ([0] => stdClass Object ([MessageText] => An object within a change description must contain one and only one property to modify. [ResponseCode] => ErrorIncorrectUpdatePropertyCount [DescriptiveLinkKey] => 0 [ResponseClass] => Error [Items] => stdClass Object ())) 

希望有人能帮助

回答

5

这里是代码,

// Update Physical Address. 
$field = new EWSType_SetItemFieldType(); 
$field->IndexedFieldURI->FieldURI = 'contacts:PhysicalAddress:Street'; 
$field->IndexedFieldURI->FieldIndex = EWSType_PhysicalAddressKeyType::HOME; 

$field->Contact = new EWSType_ContactItemType(); 
$field->Contact->PhysicalAddresses = new EWSType_PhysicalAddressDictionaryType(); 
$address = new EWSType_PhysicalAddressDictionaryEntryType(); 
$address->Key = EWSType_PhysicalAddressKeyType::HOME; 

$field->Contact->PhysicalAddresses->Entry = $address; 
$field->Contact->PhysicalAddresses->Entry->Street = $street; 

$change->Updates->SetItemField[] = $field; 

基本上你设置你的FieldURI和现场指数(一个必须记住,在更新时,你可以一次只更新一个项目),你会看到FieldURI被设置为“联系人:PhysicalAddress:Street“这是因为您一次只能更新一个项目。

接下来我们创建Contact标签,然后创建PhysicalAddresses标签,然后创建Entry标签并将其设置为Home的Key,最后我们设置Street标签。

它创建的实际XML将如下所示。

<t:SetItemField> 
<t:IndexedFieldURI FieldURI="contacts:PhysicalAddress:CountryOrRegion" FieldIndex="Business" /> 
<t:Contact> 
<t:PhysicalAddresses> 
<t:Entry Key="Business"> 
<t:CountryOrRegion> 
</t:CountryOrRegion> 
</t:Entry> 
</t:PhysicalAddresses> 
</t:Contact> 
</t:SetItemField> 

而这就是它,它然后更新街address.All你现在需要做的就是把代码在一个循环,使用开关,看你想要的地址的一部分更新和鲍勃你叔叔。

噢,好希望这可以帮助某人。

+0

感谢Philip。自从上个3-4小时以来,我遇到了同样的问题。你救了我。他们应该在某处显示您需要逐一放置密钥来更新它。 –