The Labs \ Source Viewer \ SSCLI \ System.Runtime.Serialization.Formatters \ ServerFault

  1. // ==++==
  2. //
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. //
  14. // ==--==
  15. /*============================================================
  16. **
  17. ** Class: SoapFault
  18. **
  19. **                                             
  20. **
  21. ** Purpose: Specifies information for a Soap Fault
  22. **
  23. ** Date:  June 27, 2000
  24. **
  25. ===========================================================*/
  26. namespace System.Runtime.Serialization.Formatters
  27. {
  28.     using System;
  29.     using System.Runtime.Serialization;
  30.     using System.Runtime.Remoting;
  31.     using System.Runtime.Remoting.Metadata;
  32.     using System.Globalization;
  33.     using System.Security.Permissions;
  34.    
  35.     //* Class holds soap fault information
  36.    
  37.     [Serializable(), SoapType(Embedded = true)]
  38.     [System.Runtime.InteropServices.ComVisible(true)]
  39.     public sealed class SoapFault : ISerializable
  40.     {
  41.         string faultCode;
  42.         string faultString;
  43.         string faultActor;
  44.         [SoapField(Embedded = true)]
  45.         object detail;
  46.        
  47.         public SoapFault()
  48.         {
  49.         }
  50.        
  51.         public SoapFault(string faultCode, string faultString, string faultActor, ServerFault serverFault)
  52.         {
  53.             this.faultCode = faultCode;
  54.             this.faultString = faultString;
  55.             this.faultActor = faultActor;
  56.             this.detail = serverFault;
  57.         }
  58.        
  59.         internal SoapFault(SerializationInfo info, StreamingContext context)
  60.         {
  61.             SerializationInfoEnumerator siEnum = info.GetEnumerator();
  62.            
  63.             while (siEnum.MoveNext()) {
  64.                 string name = siEnum.Name;
  65.                 object value = siEnum.Value;
  66.                 SerTrace.Log(this, "SetObjectData enum ", name, " value ", value);
  67.                 if (String.Compare(name, "faultCode", true, CultureInfo.InvariantCulture) == 0) {
  68.                     int index = ((string)value).IndexOf(':');
  69.                     if (index > -1)
  70.                         faultCode = ((string)value).Substring(++index);
  71.                     else
  72.                         faultCode = (string)value;
  73.                 }
  74.                 else if (String.Compare(name, "faultString", true, CultureInfo.InvariantCulture) == 0)
  75.                     faultString = (string)value;
  76.                 else if (String.Compare(name, "faultActor", true, CultureInfo.InvariantCulture) == 0)
  77.                     faultActor = (string)value;
  78.                 else if (String.Compare(name, "detail", true, CultureInfo.InvariantCulture) == 0)
  79.                     detail = value;
  80.             }
  81.         }
  82.        
  83.         [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
  84.         public void GetObjectData(SerializationInfo info, StreamingContext context)
  85.         {
  86.             info.AddValue("faultcode", "SOAP-ENV:" + faultCode);
  87.             info.AddValue("faultstring", faultString);
  88.             if (faultActor != null)
  89.                 info.AddValue("faultactor", faultActor);
  90.             info.AddValue("detail", detail, typeof(object));
  91.         }
  92.        
  93.         public string FaultCode {
  94.             get { return faultCode; }
  95.             set { faultCode = value; }
  96.         }
  97.        
  98.         public string FaultString {
  99.             get { return faultString; }
  100.             set { faultString = value; }
  101.         }
  102.        
  103.        
  104.         public string FaultActor {
  105.             get { return faultActor; }
  106.             set { faultActor = value; }
  107.         }
  108.        
  109.        
  110.         public object Detail {
  111.             get { return detail; }
  112.             set { detail = value; }
  113.         }
  114.     }
  115.    
  116.     [Serializable(), SoapType(Embedded = true)]
  117.     [System.Runtime.InteropServices.ComVisible(true)]
  118.     public sealed class ServerFault
  119.     {
  120.         string exceptionType;
  121.         string message;
  122.         string stackTrace;
  123.         Exception exception;
  124.        
  125.         internal ServerFault(Exception exception)
  126.         {
  127.             this.exception = exception;
  128.             //this.exceptionType = exception.GetType().AssemblyQualifiedName;
  129.             //this.message = exception.Message;
  130.         }
  131.        
  132.         public ServerFault(string exceptionType, string message, string stackTrace)
  133.         {
  134.             this.exceptionType = exceptionType;
  135.             this.message = message;
  136.             this.stackTrace = stackTrace;
  137.         }
  138.        
  139.        
  140.         public string ExceptionType {
  141.             get { return exceptionType; }
  142.             set { exceptionType = value; }
  143.         }
  144.        
  145.         public string ExceptionMessage {
  146.             get { return message; }
  147.             set { message = value; }
  148.         }
  149.        
  150.        
  151.         public string StackTrace {
  152.             get { return stackTrace; }
  153.             set { stackTrace = value; }
  154.         }
  155.        
  156.         internal Exception Exception {
  157.             get { return exception; }
  158.         }
  159.     }
  160. }

Developer Fusion