【问题标题】:How to Handle CommunicationException When Using Lists.asmx in SharePoint 2010在 SharePoint 2010 中使用 Lists.asmx 时如何处理 CommunicationException
【发布时间】:2011-08-14 17:39:41
【问题描述】:

我在 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.ValidateAuthentication(HttpWebRequest 请求,HttpWebResponse 响应,WebException responseException,HttpChannelFactory 工厂) 在 System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest 请求,HttpWebResponse 响应,HttpChannelFactory 工厂,WebException responseException) 在 System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.ProcessResponse(HttpWebResponse 响应,WebException responseException) 在 System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult 结果) 在 System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.OnGetResponse(IAsyncResult 结果) 在 System.Net.Browser.ClientHttpWebRequest.c_DisplayClassa.b_8(对象状态 2) 在 System.Threading.ThreadPool.WorkItem.doWork(对象 o) 在 System.Threading.Timer.ring()

即使我使用 try~catch,我也无法处理 CommunicationException。 所以,请告诉我如何处理 CommunicationException。

【问题讨论】:

    标签: sharepoint sharepoint-2010


    【解决方案1】:

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

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

    【讨论】:

    • 感谢您的建议。但我无法根据你的建议解决。似乎在 GetListItemsCompleted 被踢之前发生了 CommunicationException。我也无法在 try~catch 块中捕获异常。
    猜你喜欢
    • 1970-01-01
    • 2014-09-09
    • 2011-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多