Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / mscorlib / system / runtime / serialization / formatters / soapfault.cs
1 // ==++==
2 // 
3 //   Copyright (c) Microsoft Corporation.  All rights reserved.
4 // 
5 // ==--==
6 /*============================================================
7  **
8  ** Class: SoapFault
9  **
10  ** <EMAIL>Author: Peter de Jong (Microsoft)</EMAIL>
11  **
12  ** Purpose: Specifies information for a Soap Fault
13  **
14  ** Date:  June 27, 2000
15  **
16  ===========================================================*/
17 #if FEATURE_REMOTING || MOBILE_LEGACY
18 namespace System.Runtime.Serialization.Formatters
19 {
20     using System;
21     using System.Runtime.Serialization;
22     using System.Runtime.Remoting;
23     using System.Runtime.Remoting.Metadata;
24     using System.Globalization;
25     using System.Security.Permissions;
26
27     //* Class holds soap fault information
28
29 [Serializable]
30 [SoapType(Embedded=true)]    
31 [System.Runtime.InteropServices.ComVisible(true)]
32     public sealed class SoapFault : ISerializable
33     {
34         String faultCode;
35         String faultString;
36         String faultActor;
37         [SoapField(Embedded=true)] Object detail;
38
39         public SoapFault()
40         {
41         }
42
43         public SoapFault(String faultCode, String faultString, String faultActor, ServerFault serverFault)
44         {
45             this.faultCode = faultCode;
46             this.faultString = faultString;
47             this.faultActor = faultActor;
48             this.detail = serverFault;
49         }
50
51         internal SoapFault(SerializationInfo info, StreamingContext context)
52         {
53             SerializationInfoEnumerator siEnum = info.GetEnumerator();        
54
55             while(siEnum.MoveNext())
56             {
57                 String name = siEnum.Name;
58                 Object value = siEnum.Value;
59                 SerTrace.Log(this, "SetObjectData enum ",name," value ",value);
60                 if (String.Compare(name, "faultCode", true, CultureInfo.InvariantCulture) == 0)
61                 {
62                     int index = ((String)value).IndexOf(':');
63                     if (index > -1)
64                         faultCode = ((String)value).Substring(++index);
65                     else
66                         faultCode = (String)value;
67                 }
68                 else if (String.Compare(name, "faultString", true, CultureInfo.InvariantCulture) == 0)
69                     faultString = (String)value;
70                 else if (String.Compare(name, "faultActor", true, CultureInfo.InvariantCulture) == 0)
71                     faultActor = (String)value;
72                 else if (String.Compare(name, "detail", true, CultureInfo.InvariantCulture) == 0)
73                     detail = value;
74             }
75         }
76
77         [System.Security.SecurityCritical]  // auto-generated_required
78         public void GetObjectData(SerializationInfo info, StreamingContext context)
79         {
80             info.AddValue("faultcode", "SOAP-ENV:"+faultCode);
81             info.AddValue("faultstring", faultString);
82             if (faultActor != null)
83                 info.AddValue("faultactor", faultActor);
84             info.AddValue("detail", detail, typeof(Object));
85         }
86
87         public String FaultCode
88         {
89             get {return faultCode;}
90             set { faultCode = value;}
91         }
92
93         public String FaultString
94         {
95             get {return faultString;}
96             set { faultString = value;}
97         }
98
99
100         public String FaultActor
101         {
102             get {return faultActor;}
103             set { faultActor = value;}
104         }
105
106
107         public Object Detail
108         {
109             get {return detail;}
110             set {detail = value;}
111         }
112     }
113
114 [Serializable]
115 [SoapType(Embedded=true)]
116 [System.Runtime.InteropServices.ComVisible(true)]
117     public sealed class ServerFault
118     {
119         String exceptionType;
120         String message;
121         String stackTrace;
122         Exception exception;
123
124         internal ServerFault(Exception exception)
125         {
126             this.exception = exception;
127             //this.exceptionType = exception.GetType().AssemblyQualifiedName;
128             //this.message = exception.Message;
129         }
130
131         public ServerFault(String exceptionType, String message, String stackTrace)
132         {
133             this.exceptionType = exceptionType;
134             this.message = message;
135             this.stackTrace = stackTrace;
136         }
137
138
139         public String ExceptionType
140         {
141             get {return exceptionType;}
142             set { exceptionType = value;}
143         }
144         
145         public String ExceptionMessage
146         {
147             get {return message;}
148             set { message = value;}
149         }
150
151
152         public String StackTrace
153         {
154             get {return stackTrace;}
155             set {stackTrace = value;}
156         }
157
158         internal Exception Exception
159         {
160             get {return exception;}
161         }
162     }
163 }
164 #endif // FEATURE_REMOTING