在SharePoint 2010中使用Lists.asmx时如何处理CommunicationException

在SharePoint 2010中使用Lists.asmx时如何处理CommunicationException,sharepoint,sharepoint-2010,Sharepoint,Sharepoint 2010,我使用SharePoint 2010表单验证中的Lists.asmx获取listitem数据 代码是这样的 private void GetItems(string listname) { ListsService.ListsSoapClient client = new ListsService.ListsSoapClient(); appset = new AppSettings(); client.CookieContainer = appset.CookieSet

我使用SharePoint 2010表单验证中的Lists.asmx获取listitem数据

代码是这样的

private void GetItems(string listname)
{
    ListsService.ListsSoapClient client = new ListsService.ListsSoapClient();
    appset = new AppSettings();
    client.CookieContainer = appset.CookieSetting;
    client.GetListItemsAsync(listname, null, null, null, "10", null, null);

    client.GetListItemsCompleted += new EventHandler<ListsService.GetListItemsCompletedEventArgs>(client_GetListItemsCompleted);

}

void client_GetListItemsCompleted(object sender, ListsService.GetListItemsCompletedEventArgs e)
{
    listBox1.ItemsSource = from element in e.Result.Descendants(XName.Get("row", "#RowsetSchema"))
                            select new Lists
                            {
                                Title = (string)element.Attribute("ows_LinkTitle")
                            };
}
表单身份验证超时时,将引发未处理的CommunicationException。堆栈跟踪在这里

位于System.ServiceModel.Channels.HttpChannelUtilities.ValidateAuthenticationHttpWebRequest请求、HttpWebResponse响应、WebException响应Exception、HttpChannelFactory 在System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponseHttpWebRequest请求、HttpWebResponse响应、HttpChannelFactory工厂、WebException响应Exception 在System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.ProcessResponseHttpWebResponse响应中,WebException responseException 位于System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponseAsyncResult 位于System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.OnGetResponseAsyncResult 在System.Net.Browser.ClientHttpWebRequest.c_中显示ClassA.b_8对象状态2 位于System.Threading.ThreadPool.WorkItem.doWorkObject o 在System.Threading.Timer.ring

即使使用try~catch,我也无法处理通信异常。
因此,请告诉我如何处理CommunicationException。

在调用GetListItemsAsSync之前,您应该注册GetListItemsCompleted事件。另外,将GetListItemsAsync包装在try-catch块中


任何错误都将作为调用GetListItemsAsSync的异常抛出,或通过GetListItemsCompletedEventArgs报告为错误。

谢谢您的建议。但我无法用你的建议来解决问题。似乎在启动GetListItemsCompleted之前发生了CommunicationException。此外,我无法在try~catch块中捕获异常。