如何捕获 Microsoft.SharePoint.SoapServer.SoapServerException?
我对如何捕获 Microsoft.SharePoint.SoapServer.SoapServerException 的特定错误类型感到有点困惑,我将解释原因,并且我在下面提供了一个代码示例供大家查看。
如您所知,有 2 种方式与 MOSS 交互。
- 对象模型(仅在 MOSS 服务器上运行)
- Web 服务(可以在查询 MOSS 服务器的远程计算机上运行)
因此,根据代码示例,我使用 Web 服务来查询 MOSS,因此我没有安装共享点在运行这些 Web 服务的远程服务器上,如果未安装 MOSS,则无法引用 SharePoint DLL 来获取特定错误类型:Microsoft.SharePoint.SoapServer.SoapServerException。
如果我无法引用 DLL,那么我到底应该如何捕获这个特定的错误类型呢?
System.Xml.XmlNode ndListView = wsLists.GetListAndView(ListName, "");
string strListID = ndListView.ChildNodes[0].Attributes["Name"].Value;
string strViewID = ndListView.ChildNodes[1].Attributes["Name"].Value;
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
System.Xml.XmlElement batchElement = doc.CreateElement("Batch");
batchElement.SetAttribute("OnError", "Continue");
batchElement.SetAttribute("ListVersion", "1");
batchElement.SetAttribute("ViewName", strViewID);
batchElement.InnerXml = "<Method ID='1' Cmd='Update'>" +
"<Field Name='DeliveryStatus'>" + newStatus.ToString() + "</Field>" +
"<Where><Eq><FieldRef Name='ID' /><Value Type='Text'>" + id + "</Value></Eq></Where></Method>";
try
{
wsLists.UpdateListItems(strListID, batchElement);
return true;
}
catch (Microsoft.SharePoint.SoapServer.SoapServerException ex)
{
}
I am a bit perplexed on how to catch a specific error type of Microsoft.SharePoint.SoapServer.SoapServerException, I'll explain why, and I've included a code sample below for you guys to see.
As you know there are 2 ways to interact with MOSS.
- The object model (only runs on MOSS Server)
- Web Services (can be run on a remote machine querying the MOSS server)
So as per code sample I'm using web services to query MOSS, because of this I don't have sharepoint installed on the remote server running these web services and without MOSS installed its impossible to reference the SharePoint DLL to get the specific error type : Microsoft.SharePoint.SoapServer.SoapServerException.
If I can't reference the DLL then how the heck am I supposed to catch this specific error type?
System.Xml.XmlNode ndListView = wsLists.GetListAndView(ListName, "");
string strListID = ndListView.ChildNodes[0].Attributes["Name"].Value;
string strViewID = ndListView.ChildNodes[1].Attributes["Name"].Value;
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
System.Xml.XmlElement batchElement = doc.CreateElement("Batch");
batchElement.SetAttribute("OnError", "Continue");
batchElement.SetAttribute("ListVersion", "1");
batchElement.SetAttribute("ViewName", strViewID);
batchElement.InnerXml = "<Method ID='1' Cmd='Update'>" +
"<Field Name='DeliveryStatus'>" + newStatus.ToString() + "</Field>" +
"<Where><Eq><FieldRef Name='ID' /><Value Type='Text'>" + id + "</Value></Eq></Where></Method>";
try
{
wsLists.UpdateListItems(strListID, batchElement);
return true;
}
catch (Microsoft.SharePoint.SoapServer.SoapServerException ex)
{
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它实际上是一个 System.Web.Services.Protocols.SoapException
Its actually a System.Web.Services.Protocols.SoapException
参考:如何获取FaultException详细信息?
Reference: How to get FaultException details?