Fault12.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. //
  2. // Fault12.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // Copyright (C) 2006 Novell, Inc.
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. //
  30. // This file is used to generate Fault12Serializer.cs with fault-12.genxs.
  31. // To generate the file, do:
  32. // - replace _internal_ class in this file to _public_ class
  33. // - optionally you might have to remove Fault12Serializer.cs from
  34. // System.Web.Services.dll.sources.
  35. // - Build System.Web.Services.dll with make PROFILE=net_2_0.
  36. // - run genxs.exe with 2.0 libraries (the easiest way would be
  37. // to build genxs under 2.0 profile i.e. make PROFILE=net_2_0)
  38. // - Edit Fault12Serializer.cs to rename "FaultSerializer" to
  39. // "Fault12Serializer" as the name is a duplicate, and
  40. // wrap the entire code with #if NET_2_0.
  41. // - revert _public_ class in this file to _internal_ class back.
  42. //
  43. using System;
  44. using System.Xml;
  45. using System.Xml.Schema;
  46. using System.Xml.Serialization;
  47. using System.Text;
  48. using System.Collections;
  49. using System.Globalization;
  50. namespace System.Web.Services.Protocols
  51. {
  52. [XmlRoot ("Fault", Namespace = "http://www.w3.org/2003/05/soap-envelope")]
  53. [XmlType ("Fault", Namespace = "http://www.w3.org/2003/05/soap-envelope")]
  54. internal class Soap12Fault
  55. {
  56. // dummy constructor to not be rejected by genxs.
  57. public Soap12Fault ()
  58. {
  59. }
  60. public static XmlSerializer Serializer =
  61. #if NET_2_0
  62. new Fault12Serializer ();
  63. #else
  64. null;
  65. #endif
  66. #if NET_2_0
  67. public Soap12Fault (SoapException ex)
  68. {
  69. Code = new Soap12FaultCode ();
  70. Code.Value = ex.Code;
  71. if (ex.SubCode != null)
  72. Code.Subcode = CreateFaultCode (ex.SubCode);
  73. Node = ex.Node;
  74. Role = ex.Role;
  75. Reason = new Soap12FaultReason ();
  76. Soap12FaultReasonText text =
  77. new Soap12FaultReasonText ();
  78. text.XmlLang = ex.Lang;
  79. text.Value = ex.Message;
  80. Reason.Texts = new Soap12FaultReasonText [] {text};
  81. if (ex.Detail != null) {
  82. Detail = new Soap12FaultDetail ();
  83. if (ex.Detail.NodeType == XmlNodeType.Attribute)
  84. Detail.Attributes = new XmlAttribute [] {
  85. (XmlAttribute) ex.Detail};
  86. else if (ex.Detail.NodeType == XmlNodeType.Element)
  87. Detail.Children = new XmlElement [] {
  88. (XmlElement) ex.Detail};
  89. else
  90. Detail.Text = ex.Detail.Value;
  91. }
  92. }
  93. static Soap12FaultCode CreateFaultCode (SoapFaultSubCode code)
  94. {
  95. if (code == null)
  96. throw new ArgumentNullException ("code");
  97. Soap12FaultCode ret = new Soap12FaultCode ();
  98. ret.Value = code.Code;
  99. if (code.SubCode != null)
  100. ret.Subcode = CreateFaultCode (code.SubCode);
  101. return ret;
  102. }
  103. public static SoapFaultSubCode GetSoapFaultSubCode (Soap12FaultCode src)
  104. {
  105. return (src == null) ? null :
  106. new SoapFaultSubCode (src.Value, GetSoapFaultSubCode (src.Subcode));
  107. }
  108. #endif
  109. public Soap12FaultCode Code;
  110. public Soap12FaultReason Reason;
  111. [XmlElement (DataType = "anyURI")]
  112. public string Node;
  113. [XmlElement (DataType = "anyURI")]
  114. public string Role;
  115. public Soap12FaultDetail Detail;
  116. }
  117. [XmlType ("Code", Namespace = "http://www.w3.org/2003/05/soap-envelope")]
  118. internal class Soap12FaultCode
  119. {
  120. public XmlQualifiedName Value;
  121. public Soap12FaultCode Subcode;
  122. }
  123. [XmlType ("Reason", Namespace = "http://www.w3.org/2003/05/soap-envelope")]
  124. internal class Soap12FaultReason
  125. {
  126. [XmlElement ("Text", Namespace = "http://www.w3.org/2003/05/soap-envelope")]
  127. public Soap12FaultReasonText [] Texts;
  128. }
  129. [XmlType ("Text", Namespace = "http://www.w3.org/2003/05/soap-envelope")]
  130. internal class Soap12FaultReasonText
  131. {
  132. [XmlAttribute ("lang", Namespace = "http://www.w3.org/XML/1998/namespace")]
  133. public string XmlLang;
  134. [XmlText]
  135. public string Value;
  136. }
  137. [XmlType ("Detail", Namespace = "http://www.w3.org/2003/05/soap-envelope")]
  138. internal class Soap12FaultDetail
  139. {
  140. [XmlAnyAttribute]
  141. public XmlAttribute [] Attributes;
  142. [XmlAnyElement]
  143. public XmlElement [] Children;
  144. [XmlText]
  145. public string Text;
  146. }
  147. }