繁体   English   中英

如何从SharePoint 2010 Web服务获取异步的listitems

[英]How to get the listitems async from a SharePoint 2010 webservice

我正在用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);
            }

我希望你们能帮助我

当然,可以异步调用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...
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM