add ISafeSerializationData
[mcs.git] / class / System.Web.Services / System.Web.Services.Protocols / Fault.cs
blob27b1846f212e9606a78d401b32909ea787b3a056
1 //
2 // System.Web.Services.Protocols.Fault.cs
3 //
4 // Author:
5 // Lluis Sanchez Gual (lluis@ximian.com)
6 //
7 // Copyright (C) 2004 Novell, Inc.
8 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System;
32 using System.Xml;
33 using System.Xml.Schema;
34 using System.Xml.Serialization;
35 using System.Text;
36 using System.Collections;
37 using System.Globalization;
39 namespace System.Web.Services.Protocols
41 internal class Fault
43 static XmlSerializer serializer;
45 static Fault ()
47 serializer = new FaultSerializer ();
50 public Fault () {}
52 public Fault (SoapException ex)
54 faultcode = ex.Code;
55 faultstring = ex.Message;
56 faultactor = ex.Actor;
57 detail = ex.Detail;
60 [XmlElement (Namespace="")]
61 public XmlQualifiedName faultcode;
63 [XmlElement (Namespace="")]
64 public string faultstring;
66 [XmlElement (Namespace="")]
67 public string faultactor;
69 [SoapIgnore]
70 public XmlNode detail;
72 public static XmlSerializer Serializer
74 get { return serializer; }
78 internal class FaultSerializer : XmlSerializer
80 protected override void Serialize (object o, XmlSerializationWriter writer)
82 FaultWriter xsWriter = writer as FaultWriter;
83 xsWriter.WriteRoot_Fault (o);
86 protected override object Deserialize (XmlSerializationReader reader)
88 FaultReader xsReader = reader as FaultReader;
89 return xsReader.ReadRoot_Fault ();
92 protected override XmlSerializationWriter CreateWriter ()
94 return new FaultWriter ();
97 protected override XmlSerializationReader CreateReader ()
99 return new FaultReader ();
103 internal class FaultReader : XmlSerializationReader
105 public object ReadRoot_Fault ()
107 Reader.MoveToContent();
108 if (Reader.LocalName != "Fault" || Reader.NamespaceURI != WebServiceHelper.SoapEnvelopeNamespace)
109 throw CreateUnknownNodeException();
110 return ReadObject_Fault (true, true);
113 public System.Web.Services.Protocols.Fault ReadObject_Fault (bool isNullable, bool checkType)
115 System.Web.Services.Protocols.Fault ob = null;
116 if (isNullable && ReadNull()) return null;
118 if (checkType)
120 System.Xml.XmlQualifiedName t = GetXsiType();
121 if (t != null)
123 if (t.Name != "Fault" || t.Namespace != WebServiceHelper.SoapEnvelopeNamespace)
124 throw CreateUnknownTypeException(t);
128 ob = new System.Web.Services.Protocols.Fault ();
130 Reader.MoveToElement();
132 while (Reader.MoveToNextAttribute())
134 if (IsXmlnsAttribute (Reader.Name)) {
136 else {
137 UnknownNode (ob);
141 Reader.MoveToElement();
142 if (Reader.IsEmptyElement) {
143 Reader.Skip ();
144 return ob;
147 Reader.ReadStartElement();
148 Reader.MoveToContent();
150 bool b0=false, b1=false, b2=false, b3=false;
152 while (Reader.NodeType != System.Xml.XmlNodeType.EndElement)
154 if (Reader.NodeType == System.Xml.XmlNodeType.Element) {
155 if (Reader.NamespaceURI == string.Empty || Reader.NamespaceURI == WebServiceHelper.SoapEnvelopeNamespace) {
156 if (Reader.LocalName == "faultcode" && !b0) {
157 b0 = true;
158 ob.@faultcode = ReadElementQualifiedName ();
159 } else if (Reader.LocalName == "faultstring" && !b1) {
160 b1 = true;
161 ob.@faultstring = Reader.ReadElementString ();
162 } else if (Reader.LocalName == "detail" && !b3) {
163 b3 = true;
164 ob.@detail = ReadXmlNode (false);
165 } else if (Reader.LocalName == "faultactor" && !b2) {
166 b2 = true;
167 ob.@faultactor = Reader.ReadElementString ();
168 } else {
169 UnknownNode (ob);
171 } else {
172 UnknownNode (ob);
174 } else
175 UnknownNode(ob);
177 Reader.MoveToContent();
180 ReadEndElement();
182 return ob;
185 protected override void InitCallbacks ()
189 protected override void InitIDs ()
194 internal class FaultWriter : XmlSerializationWriter
196 public void WriteRoot_Fault (object o)
198 WriteStartDocument ();
199 System.Web.Services.Protocols.Fault ob = (System.Web.Services.Protocols.Fault) o;
200 TopLevelElement ();
201 WriteObject_Fault (ob, "Fault", WebServiceHelper.SoapEnvelopeNamespace, true, false, true);
204 void WriteObject_Fault (System.Web.Services.Protocols.Fault ob, string element, string namesp, bool isNullable, bool needType, bool writeWrappingElem)
206 if (ob == null)
208 if (isNullable)
209 WriteNullTagLiteral(element, namesp);
210 return;
213 if (writeWrappingElem) {
214 WriteStartElement (element, namesp, ob);
217 if (needType) WriteXsiType ("Fault", WebServiceHelper.SoapEnvelopeNamespace);
219 WriteElementQualifiedName ("faultcode", "", ob.@faultcode);
220 WriteElementString ("faultstring", "", ob.@faultstring);
221 WriteElementString ("faultactor", "", ob.@faultactor);
222 WriteElementLiteral (ob.@detail, "detail", "", false, false);
223 if (writeWrappingElem) WriteEndElement (ob);
226 protected override void InitCallbacks ()