万卷书   首页 > 电脑书籍 > Web服务器 > Web服务中的异常处理(3)
 
   XmlDocumentxmlDoc=newXmlDocument();

   //CreatetheDetailnode

   XmlNoderootNode=xmlDoc.CreateNode(XmlNodeType.Element,

   SoapException.DetailElementName.Name,

   SoapException.DetailElementName.Namespace);

   //BuildspecificdetailsfortheSoapException

   //AddfirstchildofdetailXMLelement.

   XmlNodeerrorNode=xmlDoc.CreateNode(XmlNodeType.Element,"Error",

   webServiceNamespace);

   //CreateandsetthevaluefortheErrorNumbernode

   XmlNodeerrorNumberNode=

   xmlDoc.CreateNode(XmlNodeType.Element,"ErrorNumber",

   webServiceNamespace);

   errorNumberNode.InnerText=errorNumber;

   //CreateandsetthevaluefortheErrorMessagenode

   XmlNodeerrorMessageNode=xmlDoc.CreateNode(XmlNodeType.Element,

   "ErrorMessage",

   webServiceNamespace);

   errorMessageNode.InnerText=errorMessage;

   //CreateandsetthevaluefortheErrorSourcenode

   XmlNodeerrorSourceNode=

   xmlDoc.CreateNode(XmlNodeType.Element,"ErrorSource",

   webServiceNamespace);

   errorSourceNode.InnerText=errorSource;

   //AppendtheErrorchildelementnodestotherootdetailnode.

   errorNode.AppendChild(errorNumberNode);

   errorNode.AppendChild(errorMessageNode);

   errorNode.AppendChild(errorSourceNode);

   //AppendtheDetailnodetotherootnode

   rootNode.AppendChild(errorNode);

   //Constructtheexception

   SoapExceptionsoapEx=newSoapException(errorMessage,

   faultCodeLocation,uri,

   rootNode);

   //Raisetheexceptionbacktothecaller

   returnsoapEx;

   }
上一页 下一页