Although I specify a ViewFields element in my sharepoint list service's GetListItems query, all fields are returned. The following code builds the request:
XmlDocument xmlDoc = new System.Xml.XmlDocument();
XmlNode query = xmlDoc.CreateNode(XmlNodeType.Element, "Query", "");
XmlNode viewFields = xmlDoc.CreateNode(XmlNodeType.Element, "ViewFields", "");
XmlNode queryOptions = xmlDoc.CreateNode(XmlNodeType.Element, "QueryOptions", "");
... set query ...
viewFields.InnerXml = "<FieldRef Name='LinkFilename' /><FieldRef Name='FileDirRef' /><FieldRef Name='FileLeafRef' />";
queryOptions.InnerXml = "<IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns><DateInUtc>TRUE</DateInUtc><Folder>Resource Management Tools</Folder><ViewAttributes Scope='Recursive' />";
XmlNode xmlNode = SharePointListWebService.GetListItems(
_listServiceConfigurationSettings.ListName,
string.Empty,
query,
viewFields,
null,
queryOptions,
null);
According to fiddler, this results in the following soap envelope being posted to the list service:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<listName>Shared Documents</listName>
<viewName />
<query>
<Query xmlns="">
<Where>
<And>
<Contains>
<FieldRef Name="FileLeafRef" />
<Value Type="Text">.xls</Value>
</Contains>
<Geq>
<FieldRef Name="Modified"
IncludeTimeValue="True" />
<Value Type="DateTime">2010-05-10T11:53:32Z</Value>
</Geq>
</And>
</Where>
<OrderBy>
<FieldRef Name="FileDirRef" />
</OrderBy>
</Query>
</query>
<viewFields>
<ViewFields xmlns="">
<FieldRef Name="LinkFilename" />
<FieldRef Name="FileDirRef" />
<FieldRef Name="FileLeafRef" />
</ViewFields>
</viewFields>
<queryOptions>
<QueryOptions xmlns="">
<IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns>
<DateInUtc>TRUE</DateInUtc>
<Folder>Resource Management Tools</Folder>
<ViewAttributes Scope="Recursive" />
</QueryOptions>
</queryOptions>
</GetListItems>
</soap:Body>
</soap:Envelope>
and the following soap response being returned from the service:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetListItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<GetListItemsResult>
<listitems xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'
xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
xmlns:rs='urn:schemas-microsoft-com:rowset'
xmlns:z='#RowsetSchema'>
<rs:data ItemCount="19">
<z:row ows_LinkFilename='[SENSITIVE DATA].xls'
ows_FileDirRef='278;#sites[SENSITIVE DATA]'
ows_FileLeafRef='278;#[SENSITIVE DATA].xls'
ows_MetaInfo='278;#Subject:SW| vti_parserversion:SR|12.0.0.6421 ContentTypeId:SW|0x0101006C2E647253A1074FB6079F08E5F2A395 _Author:SW|[SENSITIVE DATA] _Category:SW| vti_author:SR|[SENSITIVE DATA] _Comments:SW| vti_approvallevel:SR| vti_categories:VW| vti_cachedcustomprops:VX|vti_approvallevel vti_categories Subject vti_assignedto Keywords _Author _Category _Comments vti_assignedto:SR| Keywords:SW| vti_modifiedby:SR|[SENSITIVE DATA]'
ows__ModerationStatus='0' ows__Level='1'
ows_Last_x0020_Modified='278;#2010-06-29T18:55:38Z'
ows_ID='278' ows_owshiddenversion='53'
ows_UniqueId='278;#{0E51B2B1-89A7-4895-8ECC-0FE7D420470C}'
ows_FSObjType='278;#0'
ows_Created_x0020_Date='278;#2009-03-09T16:06:41Z'
ows_ProgId='278;#' ows_Modified='2010-06-29T18:55:37Z'
ows_FileRef='278;#sites[SENSITIVE DATA].xls'
ows_DocIcon='xls'
ows_Editor='262;#[SENSITIVE DATA]' />
</rs:data>
</listitems>
</GetListItemsResult>
</GetListItemsResponse>
</soap:Body>
</soap:Envelope>
Notice the z:row element has more fields included than I specified in my ViewFields criteria. I also set IncludeMandatoryColumns to false in my query options. Did I do something wrong or do just I not understand how ViewFields really works as I thought it would limit the fields i.e. z:row attributes returned by the SharePoint list service.