Message headers are now serialized and deserialized for MessageHeaderDescription.
[mono.git] / mcs / class / System.Web.Services / System.Web.Services.Protocols / SoapException.cs
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 //
10
11 //
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.
30 //
31
32 using System.IO;
33 using System.Runtime.Serialization;
34 using System.Xml;
35
36 namespace System.Web.Services.Protocols 
37 {
38 #if NET_2_0
39         [Serializable]
40 #endif
41         public class SoapException : SystemException 
42         {
43                 #region Fields
44
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/");
50
51                 string actor;
52                 XmlQualifiedName code;
53                 XmlNode detail;
54                 
55 #if NET_2_0
56                 string lang;
57                 string role;
58                 SoapFaultSubCode subcode;
59 #endif
60                 #endregion
61
62                 #region Constructors
63
64 #if NET_2_0
65                 public SoapException ()
66                         : this ("SOAP error", XmlQualifiedName.Empty)
67                 {
68                 }
69 #endif
70
71                 public SoapException (string message, XmlQualifiedName code)
72                         : base (message)
73                 {
74                         this.code = code;
75                 }
76
77                 public SoapException (string message, XmlQualifiedName code, Exception innerException)
78                         : base (message, innerException)
79                 {
80                         this.code = code;
81                 }
82
83                 public SoapException (string message, XmlQualifiedName code, string actor)
84                         : base (message)
85                 {
86                         this.code = code;
87                         this.actor = actor;
88                 }
89
90                 public SoapException (string message, XmlQualifiedName code, string actor, Exception innerException)
91                         : base (message, innerException)
92                 {
93                         this.code = code;
94                         this.actor = actor;
95                 }
96
97                 public SoapException (string message, XmlQualifiedName code, string actor, XmlNode detail)
98                         : base (message)
99                 {
100                         this.code = code;
101                         this.actor = actor;
102                         this.detail = detail;
103                 }
104
105                 public SoapException (string message, XmlQualifiedName code, string actor, XmlNode detail, Exception innerException)
106                         : base (message, innerException)
107                 {
108                         this.code = code;
109                         this.actor = actor;
110                         this.detail = detail;
111                 }
112
113 #if NET_2_0
114                 public SoapException (string message, XmlQualifiedName code, SoapFaultSubCode subcode)
115                         : base (message)
116                 {
117                         this.code = code;
118                         this.subcode = subcode;
119                 }
120                 
121                 public SoapException (string message, XmlQualifiedName code, string actor, string role, XmlNode detail, SoapFaultSubCode subcode, Exception innerException)
122                         : base (message, innerException)
123                 {
124                         this.code = code;
125                         this.subcode = subcode;
126                         this.detail = detail;
127                         this.actor = actor;
128                         this.role = role;
129                 }
130                 
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)
133                 {
134                         this.lang = lang;
135                 }
136
137 #if NET_2_0
138                 protected SoapException (SerializationInfo info, StreamingContext context)
139                         : base (info, context)
140                 {
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));
148                 }
149
150                 public override void GetObjectData (SerializationInfo info, StreamingContext context)
151                 {
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);
159                 }
160 #endif
161
162                 public static bool IsClientFaultCode (XmlQualifiedName code)
163                 {
164                         if (code == ClientFaultCode) return true;
165                         if (code == Soap12FaultCodes.SenderFaultCode) return true;
166                         return false;
167                 }
168
169                 public static bool IsMustUnderstandFaultCode (XmlQualifiedName code)
170                 {
171                         if (code == MustUnderstandFaultCode) return true;
172                         if (code == Soap12FaultCodes.MustUnderstandFaultCode) return true;
173                         return false;
174                 }
175                                 
176                 public static bool IsServerFaultCode (XmlQualifiedName code)
177                 {
178                         if (code == ServerFaultCode) return true;
179                         if (code == Soap12FaultCodes.ReceiverFaultCode) return true;
180                         return false;
181                 }
182                                 
183                 public static bool IsVersionMismatchFaultCode (XmlQualifiedName code)
184                 {
185                         if (code == VersionMismatchFaultCode) return true;
186                         if (code == Soap12FaultCodes.VersionMismatchFaultCode) return true;
187                         return false;
188                 }
189
190 #endif
191
192                 #endregion // Constructors
193
194                 #region Properties
195
196                 public string Actor {
197                         get { return actor; }
198                 }
199
200                 public XmlQualifiedName Code {
201                         get { return code; }
202                 }
203
204                 public XmlNode Detail {
205                         get { return detail; }
206                 }
207
208 #if NET_2_0
209                 [System.Runtime.InteropServices.ComVisible(false)]
210                 public string Lang {
211                         get { return lang; }
212                 }
213                 
214                 [System.Runtime.InteropServices.ComVisible(false)]
215                 public string Role {
216                         get { return role; }
217                 }
218                 
219                 [System.Runtime.InteropServices.ComVisible(false)]
220                 public SoapFaultSubCode SubCode {
221                         get { return subcode; }
222                 }
223                 
224                 // Same value as actor
225                 [System.Runtime.InteropServices.ComVisible(false)]
226                 public string Node {
227                         get { return actor; }
228                 }
229 #endif
230                 #endregion // Properties
231         }
232 }