我試圖用CAML查詢調用Lists.GetListItems
。當我不包含查詢參數時它工作正常,但是當我包含查詢時會出現超時錯誤。假設我的web服務被稱爲TestWebService
,代碼爲:當我包含查詢時GetListItems超時
public static void GetListItemsTest()
{
try
{
string listName = "TestList";
string[] fields = { "ID", "Title" };
string queryStr =
"<GroupBy collapse='true'>" +
"<FieldRef Name='" + fields[1] + "' />" +
"</GroupBy>" +
"<OrderBy>" +
"<FieldRef Name='ID' Ascending='False' />" +
"</OrderBy>";
XmlDocument xmlDoc = new System.Xml.XmlDocument();
XmlElement query = xmlDoc.CreateElement("Query");
XmlElement viewFields = xmlDoc.CreateElement("ViewFields");
query.InnerXml = queryStr;
viewFields.InnerXml = "";
TestWebService.Lists lists = new TestWebService.Lists();
lists.Url = "http://wss/sites/TestWebService/_vti_bin/lists.asmx";
lists.Credentials = System.Net.CredentialCache.DefaultCredentials;
XmlNode responseNode = lists.GetListItems(listName, null, query, viewFields, "1000000", null, null);
Console.WriteLine("ran successfully");
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
finally
{
Console.ReadLine();
}
}
到GetListItems
掛電話,然後引發該消息引發WebException「操作超時」。如果我改變query.InnerXml
分配:
query.InnerXml="";
然後GetListItems
成功返回responseNode
值。所以它必須與CAML查詢片段有關。
在進一步調查中,我發現GroupBy
元素是問題的根源;與OrderBy
元素註釋掉,查詢超時,並與GroupBy
元素註釋掉,查詢成功。我想知道如果GroupBy
不能處理大數據集,或者它處理得太慢;這個集合有大約20,000個元素,每個Title值通常不會超過5或6個副本。在這種情況下,LINQ會更適用嗎?或者有沒有辦法用直CAML來做到這一點?
該列表託管在SP2007上,如果有的話。檢索頁面中的項目非常耗時,每頁大約100個項目。現在我要嘗試整理沒有分組的列表,然後使用LINQ進行分組和排序。 – sigil 2012-07-13 22:01:30