2
0

SoapException.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. : base (info, context)
  122. {
  123. actor = info.GetString ("actor");
  124. code = (XmlQualifiedName) info.GetValue ("code", typeof (XmlQualifiedName));
  125. detail = new XmlDocument ().ReadNode (
  126. XmlReader.Create (new StringReader (info.GetString ("detailString"))));
  127. lang = info.GetString ("lang");
  128. role = info.GetString ("role");
  129. subcode = (SoapFaultSubCode) info.GetValue ("subcode", typeof (SoapFaultSubCode));
  130. }
  131. public override void GetObjectData (SerializationInfo info, StreamingContext context)
  132. {
  133. base.GetObjectData (info, context);
  134. info.AddValue ("actor", actor);
  135. info.AddValue ("code", code);
  136. info.AddValue ("detailString", detail.OuterXml);
  137. info.AddValue ("lang", lang);
  138. info.AddValue ("role", role);
  139. info.AddValue ("subcode", subcode);
  140. }
  141. #endif
  142. public static bool IsClientFaultCode (XmlQualifiedName code)
  143. {
  144. if (code == ClientFaultCode) return true;
  145. if (code == Soap12FaultCodes.SenderFaultCode) return true;
  146. return false;
  147. }
  148. public static bool IsMustUnderstandFaultCode (XmlQualifiedName code)
  149. {
  150. if (code == MustUnderstandFaultCode) return true;
  151. if (code == Soap12FaultCodes.MustUnderstandFaultCode) return true;
  152. return false;
  153. }
  154. public static bool IsServerFaultCode (XmlQualifiedName code)
  155. {
  156. if (code == ServerFaultCode) return true;
  157. if (code == Soap12FaultCodes.ReceiverFaultCode) return true;
  158. return false;
  159. }
  160. public static bool IsVersionMismatchFaultCode (XmlQualifiedName code)
  161. {
  162. if (code == VersionMismatchFaultCode) return true;
  163. if (code == Soap12FaultCodes.VersionMismatchFaultCode) return true;
  164. return false;
  165. }
  166. #endif
  167. #endregion // Constructors
  168. #region Properties
  169. public string Actor {
  170. get { return actor; }
  171. }
  172. public XmlQualifiedName Code {
  173. get { return code; }
  174. }
  175. public XmlNode Detail {
  176. get { return detail; }
  177. }
  178. #if NET_2_0
  179. [System.Runtime.InteropServices.ComVisible(false)]
  180. public string Lang {
  181. get { return lang; }
  182. }
  183. [System.Runtime.InteropServices.ComVisible(false)]
  184. public string Role {
  185. get { return role; }
  186. }
  187. [System.Runtime.InteropServices.ComVisible(false)]
  188. public SoapFaultSubCode SubCode {
  189. get { return subcode; }
  190. }
  191. // Same value as actor
  192. [System.Runtime.InteropServices.ComVisible(false)]
  193. public string Node {
  194. get { return actor; }
  195. }
  196. #endif
  197. #endregion // Properties
  198. }
  199. }