1 //------------------------------------------------------------------------------
2 // <copyright file="SoapException.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 //------------------------------------------------------------------------------
7 namespace System.Web.Services.Protocols {
9 using System.Collections;
10 using System.Reflection;
11 using System.Security.Permissions;
13 using System.Xml.Serialization;
14 using System.Runtime.InteropServices;
15 using System.Runtime.Serialization;
17 /// <include file='doc\SoapException.uex' path='docs/doc[@for="SoapException"]/*' />
19 /// <para>SoapException is the only mechanism for raising exceptions when a Web
20 /// Method is called over SOAP. A SoapException can either be generated
21 /// by the .Net Runtime or by a Web Service Method.
22 /// The .Net Runtime can generate an SoapException, if a response to a request
23 /// that is malformed. A Web Service Method can generate a SoapException by simply
24 /// generating an Exception within the Web Service Method, if the client accessed the method
25 /// over SOAP. Any time a Web Service Method throws an exception, that exception
26 /// is caught on the server and wrapped inside a new SoapException.</para>
29 public class SoapException : SystemException {
30 XmlQualifiedName code = XmlQualifiedName.Empty;
33 System.Xml.XmlNode detail;
34 SoapFaultSubCode subCode;
38 /// <include file='doc\SoapException.uex' path='docs/doc[@for="SoapException.ServerFaultCode"]/*' />
40 /// <para>[To be supplied.]</para>
42 public static readonly XmlQualifiedName ServerFaultCode = new XmlQualifiedName(Soap.Code.Server, Soap.Namespace);
43 /// <include file='doc\SoapException.uex' path='docs/doc[@for="SoapException.ClientFaultCode"]/*' />
45 /// <para>[To be supplied.]</para>
47 public static readonly XmlQualifiedName ClientFaultCode = new XmlQualifiedName(Soap.Code.Client, Soap.Namespace);
48 /// <include file='doc\SoapException.uex' path='docs/doc[@for="SoapException.VersionMismatchFaultCode"]/*' />
50 /// <para>[To be supplied.]</para>
52 public static readonly XmlQualifiedName VersionMismatchFaultCode = new XmlQualifiedName(Soap.Code.VersionMismatch, Soap.Namespace);
53 /// <include file='doc\SoapException.uex' path='docs/doc[@for="SoapException.MustUnderstandFaultCode"]/*' />
55 /// <para>[To be supplied.]</para>
57 public static readonly XmlQualifiedName MustUnderstandFaultCode = new XmlQualifiedName(Soap.Code.MustUnderstand, Soap.Namespace);
58 /// <include file='doc\SoapException.uex' path='docs/doc[@for="SoapException.DetailElementName"]/*' />
60 /// <para>[To be supplied.]</para>
62 // NOTE, Microsoft: The SOAP 1.1 is unclear on whether the detail element can or should be qualified.
63 // Based on consensus about the intent, we will not qualify it.
64 public static readonly XmlQualifiedName DetailElementName = new XmlQualifiedName(Soap.Element.FaultDetail, "");
66 /// <include file='doc\SoapException.uex' path='docs/doc[@for="SoapException.IsServerFaultCode"]/*' />
67 public static bool IsServerFaultCode(XmlQualifiedName code) {
68 return code == ServerFaultCode || code == Soap12FaultCodes.ReceiverFaultCode;
71 /// <include file='doc\SoapException.uex' path='docs/doc[@for="SoapException.IsClientFaultCode"]/*' />
72 public static bool IsClientFaultCode(XmlQualifiedName code) {
73 return code == ClientFaultCode || code == Soap12FaultCodes.SenderFaultCode;
76 /// <include file='doc\SoapException.uex' path='docs/doc[@for="SoapException.IsVersionMismatchFaultCode"]/*' />
77 public static bool IsVersionMismatchFaultCode(XmlQualifiedName code) {
78 return code == VersionMismatchFaultCode || code == Soap12FaultCodes.VersionMismatchFaultCode;
81 /// <include file='doc\SoapException.uex' path='docs/doc[@for="SoapException.IsMustUnderstandFaultCode"]/*' />
82 public static bool IsMustUnderstandFaultCode(XmlQualifiedName code) {
83 return code == MustUnderstandFaultCode || code == Soap12FaultCodes.MustUnderstandFaultCode;
86 /// <include file='doc\SoapException.uex' path='docs/doc[@for="SoapException.SoapException9"]/*' />
87 public SoapException() : base(null) {
90 /// <include file='doc\SoapException.uex' path='docs/doc[@for="SoapException.SoapException"]/*' />
92 /// <para>Initializes a new instance of the <see cref='System.Web.Services.Protocols.SoapException'/> class, setting <see cref='System.Exception.Message'/> to <paramref name="message"/>, <see cref='System.Web.Services.Protocols.SoapException.Code'/> to
93 /// <paramref name="code"/> and <see cref='System.Web.Services.Protocols.SoapException.Actor'/> to <paramref name="actor"/>.</para>
95 public SoapException(string message, XmlQualifiedName code, string actor) : base(message) {
100 /// <include file='doc\SoapException.uex' path='docs/doc[@for="SoapException.SoapException1"]/*' />
102 /// <para>Initializes a new instance of the <see cref='System.Web.Services.Protocols.SoapException'/> class, setting <see cref='System.Exception.Message'/> to
103 /// <paramref name="message"/>, <see cref='System.Web.Services.Protocols.SoapException.Code'/> to <paramref name="code,
104 /// "/><see cref='System.Web.Services.Protocols.SoapException.Actor'/> to <paramref name="actor
105 /// "/>and <see cref='System.Exception.InnerException'/> to <paramref name="innerException"/> .</para>
107 public SoapException(string message, XmlQualifiedName code, string actor, Exception innerException) : base(message, innerException) {
112 /// <include file='doc\SoapException.uex' path='docs/doc[@for="SoapException.SoapException2"]/*' />
114 /// <para>Initializes a new instance of the <see cref='System.Web.Services.Protocols.SoapException'/> class, setting <see cref='System.Exception.Message'/> to
115 /// <paramref name="message "/>and<paramref name=" "/>
116 /// <see cref='System.Web.Services.Protocols.SoapException.Code'/>
117 /// to <paramref name="code"/>.</para>
119 public SoapException(string message, XmlQualifiedName code) : base(message) {
123 /// <include file='doc\SoapException.uex' path='docs/doc[@for="SoapException.SoapException3"]/*' />
125 /// <para>Initializes a new instance of the <see cref='System.Web.Services.Protocols.SoapException'/> class, setting <see cref='System.Exception.Message'/> to
126 /// <paramref name="message"/>, <see cref='System.Web.Services.Protocols.SoapException.Code'/> to <paramref name="code "/>and
127 /// <see cref='System.Exception.InnerException'/>
128 /// to <paramref name="innerException"/>.</para>
130 public SoapException(string message, XmlQualifiedName code, Exception innerException) : base(message, innerException) {
134 /// <include file='doc\SoapException.uex' path='docs/doc[@for="SoapException.SoapException4"]/*' />
136 /// <para>[To be supplied.]</para>
138 public SoapException(string message, XmlQualifiedName code, string actor, System.Xml.XmlNode detail) : base(message) {
141 this.detail = detail;
144 /// <include file='doc\SoapException.uex' path='docs/doc[@for="SoapException.SoapException5"]/*' />
146 /// <para>[To be supplied.]</para>
148 public SoapException(string message, XmlQualifiedName code, string actor, System.Xml.XmlNode detail, Exception innerException) : base(message, innerException) {
151 this.detail = detail;
154 /// <include file='doc\SoapException.uex' path='docs/doc[@for="SoapException.SoapException6"]/*' />
156 /// <para>[To be supplied.]</para>
158 public SoapException(string message, XmlQualifiedName code, SoapFaultSubCode subCode) : base(message) {
160 this.subCode = subCode;
163 /// <include file='doc\SoapException.uex' path='docs/doc[@for="SoapException.SoapException7"]/*' />
165 /// <para>[To be supplied.]</para>
167 public SoapException(string message, XmlQualifiedName code, string actor, string role, System.Xml.XmlNode detail, SoapFaultSubCode subCode, Exception innerException) : base(message, innerException) {
171 this.detail = detail;
172 this.subCode = subCode;
175 /// <include file='doc\SoapException.uex' path='docs/doc[@for="SoapException.SoapException8"]/*' />
177 /// <para>[To be supplied.]</para>
179 public SoapException(string message, XmlQualifiedName code, string actor, string role, string lang, System.Xml.XmlNode detail, SoapFaultSubCode subCode, Exception innerException) : base(message, innerException) {
183 this.detail = detail;
185 this.subCode = subCode;
188 protected SoapException(SerializationInfo info, StreamingContext context) : base(info, context) {
189 IDictionary list = base.Data;
190 code = (XmlQualifiedName)list["code"];
191 actor = (string)list["actor"];
192 role = (string)list["role"];
198 subCode = (SoapFaultSubCode)list["subCode"];
199 lang = (string)list["lang"];
202 /// <include file='doc\SoapException.uex' path='docs/doc[@for="SoapException.Actor"]/*' />
204 /// The piece of code that caused the exception.
205 /// Typically, an URL to a Web Service Method.
207 public string Actor {
208 get { return actor == null ? string.Empty : actor; }
211 /// <include file='doc\SoapException.uex' path='docs/doc[@for="SoapException.Code"]/*' />
213 /// <para>The type of error that occurred.</para>
215 public XmlQualifiedName Code {
219 // the <soap:detail> element. If null, the <detail> element was not present in the <fault> element.
220 /// <include file='doc\SoapException.uex' path='docs/doc[@for="SoapException.Detail"]/*' />
222 /// <para>[To be supplied.]</para>
224 public System.Xml.XmlNode Detail {
230 /// <include file='doc\SoapException.uex' path='docs/doc[@for="SoapException.Lang"]/*' />
232 /// <para>[To be supplied.]</para>
236 get { return lang == null ? string.Empty : lang; }
239 // this is semantically the same as Actor so we use the same field but we offer a second property
240 // in case the user is thinking in soap 1.2
241 /// <include file='doc\SoapException.uex' path='docs/doc[@for="SoapException.Node"]/*' />
243 /// <para>[To be supplied.]</para>
247 get { return actor == null ? string.Empty : actor; }
250 /// <include file='doc\SoapException.uex' path='docs/doc[@for="SoapException.Role"]/*' />
252 /// <para>[To be supplied.]</para>
256 get { return role == null ? string.Empty : role; }
259 /// <include file='doc\SoapException.uex' path='docs/doc[@for="SoapException.SubCode"]/*' />
261 /// <para>[To be supplied.]</para>
264 public SoapFaultSubCode SubCode {
270 // helper function that allows us to pass dummy subCodes around but clear them before they get to the user
271 internal void ClearSubCode() {
273 subCode = subCode.SubCode;
276 [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
277 public override void GetObjectData(SerializationInfo info, StreamingContext context) {
278 IDictionary list = Data;
280 list["actor"] = Actor;
287 list["subCode"] = SubCode;
290 base.GetObjectData(info, context);
293 static SoapException CreateSuppressedException(SoapProtocolVersion soapVersion, string message, Exception innerException) {
294 return new SoapException(Res.GetString(Res.WebSuppressedExceptionMessage),
295 soapVersion == SoapProtocolVersion.Soap12
296 ? new XmlQualifiedName(Soap12.Code.Receiver, Soap12.Namespace)
297 : new XmlQualifiedName(Soap.Code.Server, Soap.Namespace));
300 internal static SoapException Create(SoapProtocolVersion soapVersion, string message, XmlQualifiedName code,
301 string actor, string role, System.Xml.XmlNode detail,
302 SoapFaultSubCode subCode, Exception innerException) {
303 if (System.Web.Services.Configuration.WebServicesSection.Current.Diagnostics.SuppressReturningExceptions) {
304 return CreateSuppressedException(soapVersion, Res.GetString(Res.WebSuppressedExceptionMessage), innerException);
307 return new SoapException(message, code, actor, role, detail, subCode, innerException);
310 internal static SoapException Create(SoapProtocolVersion soapVersion, string message, XmlQualifiedName code, Exception innerException) {
311 if (System.Web.Services.Configuration.WebServicesSection.Current.Diagnostics.SuppressReturningExceptions) {
312 return CreateSuppressedException(soapVersion, Res.GetString(Res.WebSuppressedExceptionMessage), innerException);
315 return new SoapException(message, code, innerException);