
Using ItemShape in a GetItem Request
Although most developers do not hand-code the XML for a Web service method call, it is useful to understand the XML that is generated by the proxy. Listing 3 shows a GetItem request that contains ItemShape.
Listing 3 GetItem request that uses ItemShape
<GetItem >
<ItemShape>
<t:BaseShape>IdOnly</t:BaseShape>
<t:AdditionalProperties>
<t:FieldURI FieldURI="item:Subject"/>
<t:FieldURI FieldURI="item:IsDraft"/>
</t:AdditionalProperties>
</ItemShape>
<ItemIds>
<t:ItemId Id="AAAcABRN0Zjag..." ChangeKey="BXAAANYX..." />
</ItemIds>
</GetItem >
In this example, the ItemShape element only includes BaseShape and AdditionalProperties child elements. The IncludeMimeContent and BodyType elements are optional and are not specified. The response to this request will include the following three properties:
-
ItemId (specified in BaseShape).
-
Subject (specified in AdditionalProperties).
-
IsDraft (specified in AdditionalProperties).
As you can see, properties under AdditionalProperties are identified by field URI. The field URIs for the most common properties are contained in the schema. For properties that are not listed in the schema, use the ExtendedFieldURI. For more information about the AdditionalProperties element, see AdditionalProperties.
Listing 4 shows an example of proxy code that specifies the ItemShape element that is shown in Listing 3.
Listing 4 GetItem request that uses ItemShape (proxy code)
GetItemType request = new GetItemType();
// Set the response shape.
request.ItemShape = new ItemResponseShapeType();
// Set BaseShape to IdOnly.
request.ItemShape.BaseShape = DefaultShapeNamesType.IdOnly;
// Include subject and isDraft properties in AdditionalProperties.
PathToUnindexedFieldType subject = new PathToUnindexedFieldType();
subject.FieldURI = UnindexedFieldURIType.itemSubject;
PathToUnindexedFieldType isDraft = new PathToUnindexedFieldType();
isDraft.FieldURI = UnindexedFieldURIType.itemIsDraft;
BasePathToElementType[] AdditionalProperties = new BasePathToElementType[] { subject, isDraft };
request.ItemShape.AdditionalProperties = additionalProperties;
// Set up the array of item IDs to retrieve (only one item in this example).
ItemIdType itemId = new ItemIdType();
itemId.Id = id;
request.ItemIds = new BaseItemIdType[1];
request.ItemIds[0] = itemId;
// Call the GetItem EWS method and pass in the request that was just created.
GetItemResponseType response = this.service.GetItem(request);
GetItem Response
Finally, here’s the response that was received from the server. As expected, it returns three properties of the item: ItemId, Subject, and IsDraft.
Listing 5 GetItem response
<GetItemResponse xmlns:m=".../messages"
xmlns:t=".../types"
xmlns=".../messages">
<m:ResponseMessages>
<m:GetItemResponseMessage ResponseClass="Success">
<m:ResponseCode>No Error</m:ResponseCode>
<m:Items>
<t:Message>
<t:ItemId Id=" AAAcABRN0Zjag..." ChangeKey=" BXAAANYX..." />
<t: Subject>This is the e-mail subject</t:Subject>
<t:IsDraft>false</t:IsDraft>
</t:Message>
</m:Items>
</m:GetItemResponseMessage>
</m:ResponseMessages>
</GetItemResponse>