I am developing a Web api in C#. In the Webapi I make a call to a SharePoint webservice.
In the method i use the method listservice.GetListItems. The problem is that it isn't async and i would like to have it async. Is there a possiblity to make it async?
//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);
}
I hope you guys can help me me
Sure, SharePoint Web Services methods could be invoked asynchronously , the following example demonstrates how to convert your example:
using (var listService = GetListService(webUri,userName,password))
{
listService.GetListAsync(listName, listName);
listService.GetListCompleted += ProcessListResult;
}
where
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...
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.