我正在用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);
}
我希望你们能帮帮我吧
答案 0 :(得分:0)
当然,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...
}