2010-06-21 Marek Habersack <mhabersack@novell.com>
[mcs.git] / class / System.Web.Services / System.Web.Services.Protocols / SoapException.cs
blobb81332a4800e3f0df15b0b5150e5f187524efd17
1 //
2 // System.Web.Services.Protocols.SoapException.cs
3 //
4 // Author:
5 // Tim Coleman (tim@timcoleman.com)
6 // Lluis Sanchez Gual (lluis@novell.com)
7 //
8 // Copyright (C) Tim Coleman, 2002
9 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.IO;
33 using System.Runtime.Serialization;
34 using System.Xml;
36 namespace System.Web.Services.Protocols
38 #if NET_2_0
39 [Serializable]
40 #endif
41 public class SoapException : SystemException
43 #region Fields
45 public static readonly XmlQualifiedName ClientFaultCode = new XmlQualifiedName ("Client", "http://schemas.xmlsoap.org/soap/envelope/");
46 public static readonly XmlQualifiedName DetailElementName = new XmlQualifiedName ("detail");
47 public static readonly XmlQualifiedName MustUnderstandFaultCode = new XmlQualifiedName ("MustUnderstand", "http://schemas.xmlsoap.org/soap/envelope/");
48 public static readonly XmlQualifiedName ServerFaultCode = new XmlQualifiedName ("Server", "http://schemas.xmlsoap.org/soap/envelope/");
49 public static readonly XmlQualifiedName VersionMismatchFaultCode = new XmlQualifiedName ("VersionMismatch", "http://schemas.xmlsoap.org/soap/envelope/");
51 string actor;
52 XmlQualifiedName code;
53 XmlNode detail;
55 #if NET_2_0
56 string lang;
57 string role;
58 SoapFaultSubCode subcode;
59 #endif
60 #endregion
62 #region Constructors
64 #if NET_2_0
65 public SoapException ()
66 : this ("SOAP error", XmlQualifiedName.Empty)
69 #endif
71 public SoapException (string message, XmlQualifiedName code)
72 : base (message)
74 this.code = code;
77 public SoapException (string message, XmlQualifiedName code, Exception innerException)
78 : base (message, innerException)
80 this.code = code;
83 public SoapException (string message, XmlQualifiedName code, string actor)
84 : base (message)
86 this.code = code;
87 this.actor = actor;
90 public SoapException (string message, XmlQualifiedName code, string actor, Exception innerException)
91 : base (message, innerException)
93 this.code = code;
94 this.actor = actor;
97 public SoapException (string message, XmlQualifiedName code, string actor, XmlNode detail)
98 : base (message)
100 this.code = code;
101 this.actor = actor;
102 this.detail = detail;
105 public SoapException (string message, XmlQualifiedName code, string actor, XmlNode detail, Exception innerException)
106 : base (message, innerException)
108 this.code = code;
109 this.actor = actor;
110 this.detail = detail;
113 #if NET_2_0
114 public SoapException (string message, XmlQualifiedName code, SoapFaultSubCode subcode)
115 : base (message)
117 this.code = code;
118 this.subcode = subcode;
121 public SoapException (string message, XmlQualifiedName code, string actor, string role, XmlNode detail, SoapFaultSubCode subcode, Exception innerException)
122 : base (message, innerException)
124 this.code = code;
125 this.subcode = subcode;
126 this.detail = detail;
127 this.actor = actor;
128 this.role = role;
131 public SoapException (string message, XmlQualifiedName code, string actor, string role, string lang, XmlNode detail, SoapFaultSubCode subcode, Exception innerException)
132 : this (message, code, actor, role, detail, subcode, innerException)
134 this.lang = lang;
137 #if NET_2_0
138 protected SoapException (SerializationInfo info, StreamingContext context)
139 : base (info, context)
141 actor = info.GetString ("actor");
142 code = (XmlQualifiedName) info.GetValue ("code", typeof (XmlQualifiedName));
143 detail = new XmlDocument ().ReadNode (
144 XmlReader.Create (new StringReader (info.GetString ("detailString"))));
145 lang = info.GetString ("lang");
146 role = info.GetString ("role");
147 subcode = (SoapFaultSubCode) info.GetValue ("subcode", typeof (SoapFaultSubCode));
150 public override void GetObjectData (SerializationInfo info, StreamingContext context)
152 base.GetObjectData (info, context);
153 info.AddValue ("actor", actor);
154 info.AddValue ("code", code);
155 info.AddValue ("detailString", detail.OuterXml);
156 info.AddValue ("lang", lang);
157 info.AddValue ("role", role);
158 info.AddValue ("subcode", subcode);
160 #endif
162 public static bool IsClientFaultCode (XmlQualifiedName code)
164 if (code == ClientFaultCode) return true;
165 if (code == Soap12FaultCodes.SenderFaultCode) return true;
166 return false;
169 public static bool IsMustUnderstandFaultCode (XmlQualifiedName code)
171 if (code == MustUnderstandFaultCode) return true;
172 if (code == Soap12FaultCodes.MustUnderstandFaultCode) return true;
173 return false;
176 public static bool IsServerFaultCode (XmlQualifiedName code)
178 if (code == ServerFaultCode) return true;
179 if (code == Soap12FaultCodes.ReceiverFaultCode) return true;
180 return false;
183 public static bool IsVersionMismatchFaultCode (XmlQualifiedName code)
185 if (code == VersionMismatchFaultCode) return true;
186 if (code == Soap12FaultCodes.VersionMismatchFaultCode) return true;
187 return false;
190 #endif
192 #endregion // Constructors
194 #region Properties
196 public string Actor {
197 get { return actor; }
200 public XmlQualifiedName Code {
201 get { return code; }
204 public XmlNode Detail {
205 get { return detail; }
208 #if NET_2_0
209 [System.Runtime.InteropServices.ComVisible(false)]
210 public string Lang {
211 get { return lang; }
214 [System.Runtime.InteropServices.ComVisible(false)]
215 public string Role {
216 get { return role; }
219 [System.Runtime.InteropServices.ComVisible(false)]
220 public SoapFaultSubCode SubCode {
221 get { return subcode; }
224 // Same value as actor
225 [System.Runtime.InteropServices.ComVisible(false)]
226 public string Node {
227 get { return actor; }
229 #endif
230 #endregion // Properties