Fault12.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. Code.Subcode = CreateFaultCode (ex.SubCode);
  72. Node = ex.Node;
  73. Role = ex.Role;
  74. Reason = new Soap12FaultReason ();
  75. Soap12FaultReasonText text =
  76. new Soap12FaultReasonText ();
  77. text.XmlLang = ex.Lang;
  78. text.Value = ex.Message;
  79. Reason.Texts = new Soap12FaultReasonText [] {text};
  80. if (ex.Detail != null) {
  81. Detail = new Soap12FaultDetail ();
  82. if (ex.Detail.NodeType == XmlNodeType.Attribute)
  83. Detail.Attributes = new XmlAttribute [] {
  84. (XmlAttribute) ex.Detail};
  85. else if (ex.Detail.NodeType == XmlNodeType.Element)
  86. Detail.Children = new XmlElement [] {
  87. (XmlElement) ex.Detail};
  88. else
  89. Detail.Text = ex.Detail.Value;
  90. }
  91. }
  92. static Soap12FaultCode CreateFaultCode (SoapFaultSubCode code)
  93. {
  94. Soap12FaultCode ret = new Soap12FaultCode ();
  95. ret.Value = code.Code;
  96. if (code.SubCode != null)
  97. ret.Subcode = CreateFaultCode (code.SubCode);
  98. return ret;
  99. }
  100. public static SoapFaultSubCode GetSoapFaultSubCode (Soap12FaultCode src)
  101. {
  102. return (src == null) ? null :
  103. new SoapFaultSubCode (src.Value, GetSoapFaultSubCode (src.Subcode));
  104. }
  105. #endif
  106. public Soap12FaultCode Code;
  107. public Soap12FaultReason Reason;
  108. [XmlElement (DataType = "anyURI")]
  109. public string Node;
  110. [XmlElement (DataType = "anyURI")]
  111. public string Role;
  112. public Soap12FaultDetail Detail;
  113. }
  114. [XmlType ("Code", Namespace = "http://www.w3.org/2003/05/soap-envelope")]
  115. internal class Soap12FaultCode
  116. {
  117. public XmlQualifiedName Value;
  118. public Soap12FaultCode Subcode;
  119. }
  120. [XmlType ("Reason", Namespace = "http://www.w3.org/2003/05/soap-envelope")]
  121. internal class Soap12FaultReason
  122. {
  123. [XmlElement ("Text", Namespace = "http://www.w3.org/2003/05/soap-envelope")]
  124. public Soap12FaultReasonText [] Texts;
  125. }
  126. [XmlType ("Text", Namespace = "http://www.w3.org/2003/05/soap-envelope")]
  127. internal class Soap12FaultReasonText
  128. {
  129. [XmlAttribute ("lang", Namespace = "http://www.w3.org/XML/1998/namespace")]
  130. public string XmlLang;
  131. [XmlText]
  132. public string Value;
  133. }
  134. [XmlType ("Detail", Namespace = "http://www.w3.org/2003/05/soap-envelope")]
  135. internal class Soap12FaultDetail
  136. {
  137. [XmlAnyAttribute]
  138. public XmlAttribute [] Attributes;
  139. [XmlAnyElement]
  140. public XmlElement [] Children;
  141. [XmlText]
  142. public string Text;
  143. }
  144. }