How to catch a Microsoft.SharePoint.SoapServer.SoapServerException?
I am a b开发者_如何转开发it 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)
{
}
Its actually a System.Web.Services.Protocols.SoapException
Reference: How to get FaultException details?
catch (FaultException fe)
{
MessageFault msgFault = fe.CreateMessageFault();
XmlElement elm = msgFault.GetDetail<XmlElement>();
var exceptionDetails = elm.InnerText;
}
精彩评论