5

我正忙于编写一些代码,这些代码将通过 PHPEWS 更新 Microsoft Exchange 服务器上的物理地址;

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

这是我的代码。

// 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 ( ) ) ) 

希望有人能帮忙

4

1 回答 1

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 设置为“contacts:PhysicalAddress:Street”,这是因为您只能在以下位置更新一项一次。

接下来我们创建Contact 标签,然后是PhysicalAddresses 标签,然后是Entry 标签,并给它Home 的键,最后我们设置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>

就是这样,然后它会更新街道地址。您现在需要做的就是将代码放入一个循环中,使用开关查看您要更新地址的哪一部分并让您的叔叔鲍勃。

哦,希望这对某人有所帮助。

于 2012-11-19T19:24:03.860 回答