SoapException.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. //
  2. // System.Web.Services.Protocols.SoapException.cs
  3. //
  4. // Author:
  5. // Tim Coleman ([email protected])
  6. // Lluis Sanchez Gual ([email protected])
  7. //
  8. // Copyright (C) Tim Coleman, 2002
  9. //
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining
  12. // a copy of this software and associated documentation files (the
  13. // "Software"), to deal in the Software without restriction, including
  14. // without limitation the rights to use, copy, modify, merge, publish,
  15. // distribute, sublicense, and/or sell copies of the Software, and to
  16. // permit persons to whom the Software is furnished to do so, subject to
  17. // the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. //
  30. using System.IO;
  31. using System.Runtime.Serialization;
  32. using System.Xml;
  33. namespace System.Web.Services.Protocols
  34. {
  35. #if NET_2_0
  36. [Serializable]
  37. #endif
  38. public class SoapException : SystemException
  39. {
  40. #region Fields
  41. public static readonly XmlQualifiedName ClientFaultCode = new XmlQualifiedName ("Client", "http://schemas.xmlsoap.org/soap/envelope/");
  42. public static readonly XmlQualifiedName DetailElementName = new XmlQualifiedName ("detail");
  43. public static readonly XmlQualifiedName MustUnderstandFaultCode = new XmlQualifiedName ("MustUnderstand", "http://schemas.xmlsoap.org/soap/envelope/");
  44. public static readonly XmlQualifiedName ServerFaultCode = new XmlQualifiedName ("Server", "http://schemas.xmlsoap.org/soap/envelope/");
  45. public static readonly XmlQualifiedName VersionMismatchFaultCode = new XmlQualifiedName ("VersionMismatch", "http://schemas.xmlsoap.org/soap/envelope/");
  46. string actor;
  47. XmlQualifiedName code;
  48. XmlNode detail;
  49. #if NET_2_0
  50. string lang;
  51. string role;
  52. SoapFaultSubCode subcode;
  53. #endif
  54. #endregion
  55. #region Constructors
  56. #if NET_2_0
  57. public SoapException ()
  58. : this ("SOAP error", XmlQualifiedName.Empty)
  59. {
  60. }
  61. #endif
  62. public SoapException (string message, XmlQualifiedName code)
  63. : base (message)
  64. {
  65. this.code = code;
  66. }
  67. public SoapException (string message, XmlQualifiedName code, Exception innerException)
  68. : base (message, innerException)
  69. {
  70. this.code = code;
  71. }
  72. public SoapException (string message, XmlQualifiedName code, string actor)
  73. : base (message)
  74. {
  75. this.code = code;
  76. this.actor = actor;
  77. }
  78. public SoapException (string message, XmlQualifiedName code, string actor, Exception innerException)
  79. : base (message, innerException)
  80. {
  81. this.code = code;
  82. this.actor = actor;
  83. }
  84. public SoapException (string message, XmlQualifiedName code, string actor, XmlNode detail)
  85. : base (message)
  86. {
  87. this.code = code;
  88. this.actor = actor;
  89. this.detail = detail;
  90. }
  91. public SoapException (string message, XmlQualifiedName code, string actor, XmlNode detail, Exception innerException)
  92. : base (message, innerException)
  93. {
  94. this.code = code;
  95. this.actor = actor;
  96. this.detail = detail;
  97. }
  98. #if NET_2_0
  99. public SoapException (string message, XmlQualifiedName code, SoapFaultSubCode subcode)
  100. : base (message)
  101. {
  102. this.code = code;
  103. this.subcode = subcode;
  104. }
  105. public SoapException (string message, XmlQualifiedName code, string actor, string role, XmlNode detail, SoapFaultSubCode subcode, Exception innerException)
  106. : base (message, innerException)
  107. {
  108. this.code = code;
  109. this.subcode = subcode;
  110. this.detail = detail;
  111. this.actor = actor;
  112. this.role = role;
  113. }
  114. public SoapException (string message, XmlQualifiedName code, string actor, string role, string lang, XmlNode detail, SoapFaultSubCode subcode, Exception innerException)
  115. : this (message, code, actor, role, detail, subcode, innerException)
  116. {
  117. this.lang = lang;
  118. }
  119. #if NET_2_0
  120. protected SoapException (SerializationInfo info, StreamingContext context)
  121. {
  122. actor = info.GetString ("actor");
  123. code = (XmlQualifiedName) info.GetValue ("code", typeof (XmlQualifiedName));
  124. detail = new XmlDocument ().ReadNode (
  125. XmlReader.Create (new StringReader (info.GetString ("detailString"))));
  126. lang = info.GetString ("lang");
  127. role = info.GetString ("role");
  128. subcode = (SoapFaultSubCode) info.GetValue ("subcode", typeof (SoapFaultSubCode));
  129. }
  130. public override void GetObjectData (SerializationInfo info, StreamingContext context)
  131. {
  132. base.GetObjectData (info, context);
  133. info.AddValue ("actor", actor);
  134. info.AddValue ("code", code);
  135. info.AddValue ("detailString", detail.OuterXml);
  136. info.AddValue ("lang", lang);
  137. info.AddValue ("role", role);
  138. info.AddValue ("subcode", subcode);
  139. }
  140. #endif
  141. public static bool IsClientFaultCode (XmlQualifiedName code)
  142. {
  143. if (code == ClientFaultCode) return true;
  144. if (code == Soap12FaultCodes.SenderFaultCode) return true;
  145. return false;
  146. }
  147. public static bool IsMustUnderstandFaultCode (XmlQualifiedName code)
  148. {
  149. if (code == MustUnderstandFaultCode) return true;
  150. if (code == Soap12FaultCodes.MustUnderstandFaultCode) return true;
  151. return false;
  152. }
  153. public static bool IsServerFaultCode (XmlQualifiedName code)
  154. {
  155. if (code == ServerFaultCode) return true;
  156. if (code == Soap12FaultCodes.ReceiverFaultCode) return true;
  157. return false;
  158. }
  159. public static bool IsVersionMismatchFaultCode (XmlQualifiedName code)
  160. {
  161. if (code == VersionMismatchFaultCode) return true;
  162. if (code == Soap12FaultCodes.VersionMismatchFaultCode) return true;
  163. return false;
  164. }
  165. #endif
  166. #endregion // Constructors
  167. #region Properties
  168. public string Actor {
  169. get { return actor; }
  170. }
  171. public XmlQualifiedName Code {
  172. get { return code; }
  173. }
  174. public XmlNode Detail {
  175. get { return detail; }
  176. }
  177. #if NET_2_0
  178. [System.Runtime.InteropServices.ComVisible(false)]
  179. public string Lang {
  180. get { return lang; }
  181. }
  182. [System.Runtime.InteropServices.ComVisible(false)]
  183. public string Role {
  184. get { return role; }
  185. }
  186. [System.Runtime.InteropServices.ComVisible(false)]
  187. public SoapFaultSubCode SubCode {
  188. get { return subcode; }
  189. }
  190. // Same value as actor
  191. [System.Runtime.InteropServices.ComVisible(false)]
  192. public string Node {
  193. get { return actor; }
  194. }
  195. #endif
  196. #endregion // Properties
  197. }
  198. }