【问题标题】:How to get the listitems async from a SharePoint 2010 webservice如何从 SharePoint 2010 Web 服务中异步获取列表项
【发布时间】:2015-07-31 09:08:55
【问题描述】:

我正在用 C# 开发一个 Web api。在 Webapi 中,我调用了 SharePoint Web 服务。

在方法中,我使用方法 listservice.GetListItems。问题是它不是异步的,我想让它异步。是否有可能使其异步?

 //create listservice instance
            var listService = GetListService();
            //Get the listName and rowlimit
            string rowLimit = MaxItemsList;

            //Create elements for the faq list
            XmlElement query = xmlDoc.CreateElement("Query");
            XmlElement viewFields = xmlDoc.CreateElement("ViewFields");
            XmlElement queryOptions = xmlDoc.CreateElement("QueryOptions");
            var sPList = listService.GetList(listName);
            if (sPList != null)
            {
                //get the faq items
                return listService.GetListItems(listName, string.Empty,   query, viewFields, rowLimit,
                    queryOptions, null);
            }

希望大家帮帮我

【问题讨论】:

    标签: c# web-services sharepoint asynchronous sharepoint-2010


    【解决方案1】:

    当然,SharePoint Web Services 方法可以异步调用,以下示例演示了如何转换您的示例:

    using (var listService = GetListService(webUri,userName,password))
    {
         listService.GetListAsync(listName, listName);
         listService.GetListCompleted += ProcessListResult;
    }
    

    在哪里

        static void ProcessListResult(object sender, GetListCompletedEventArgs e)
        {
            var proxy = sender as Contoso.Lists;
            var listName = e.UserState as string;
    
            var xmlDoc = new System.Xml.XmlDocument();
            var ndQuery = xmlDoc.CreateElement("Query");
            var ndViewFields = xmlDoc.CreateElement("ViewFields");
            var ndQueryOptions = xmlDoc.CreateElement("QueryOptions");
            proxy.GetListItemsAsync(listName, null, ndQuery, ndViewFields, null, ndQueryOptions, null);
            proxy.GetListItemsCompleted += ProcessListItemsResult;
        }
    
        static void ProcessListItemsResult(object sender, GetListItemsCompletedEventArgs e)
        {
            //omitted for clarity...
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-05
      • 2011-09-28
      • 2011-07-18
      • 1970-01-01
      • 1970-01-01
      • 2012-03-25
      相关资源
      最近更新 更多