2 // System.Web.Services.Protocols.Fault.cs
5 // Lluis Sanchez Gual (lluis@ximian.com)
7 // Copyright (C) 2004 Novell, Inc.
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:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
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.
33 using System.Xml.Schema;
34 using System.Xml.Serialization;
36 using System.Collections;
37 using System.Globalization;
39 namespace System.Web.Services.Protocols
43 static XmlSerializer serializer;
47 serializer = new FaultSerializer ();
52 public Fault (SoapException ex)
55 faultstring = ex.Message;
56 faultactor = ex.Actor;
60 [XmlElement (Namespace="")]
61 public XmlQualifiedName faultcode;
63 [XmlElement (Namespace="")]
64 public string faultstring;
66 [XmlElement (Namespace="")]
67 public string faultactor;
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 != "http://schemas.xmlsoap.org/soap/envelope/")
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;
120 System.Xml.XmlQualifiedName t = GetXsiType();
123 if (t.Name != "Fault" || t.Namespace != "http://schemas.xmlsoap.org/soap/envelope/")
124 throw CreateUnknownTypeException(t);
128 ob = new System.Web.Services.Protocols.Fault ();
130 Reader.MoveToElement();
132 while (Reader.MoveToNextAttribute())
134 if (IsXmlnsAttribute (Reader.Name)) {
141 Reader.MoveToElement();
142 if (Reader.IsEmptyElement) {
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)
156 if (Reader.LocalName == "faultcode" && Reader.NamespaceURI == "" && !b0) {
158 ob.@faultcode = ReadElementQualifiedName ();
160 else if (Reader.LocalName == "faultstring" && Reader.NamespaceURI == "" && !b1) {
162 ob.@faultstring = Reader.ReadElementString ();
164 else if (Reader.LocalName == "detail" && Reader.NamespaceURI == "http://schemas.xmlsoap.org/soap/envelope/" && !b3) {
166 ob.@detail = ReadXmlNode (true);
168 else if (Reader.LocalName == "faultactor" && Reader.NamespaceURI == "" && !b2) {
170 ob.@faultactor = Reader.ReadElementString ();
179 Reader.MoveToContent();
187 protected override void InitCallbacks ()
191 protected override void InitIDs ()
196 internal class FaultWriter : XmlSerializationWriter
198 public void WriteRoot_Fault (object o)
200 WriteStartDocument ();
201 System.Web.Services.Protocols.Fault ob = (System.Web.Services.Protocols.Fault) o;
203 WriteObject_Fault (ob, "Fault", "http://schemas.xmlsoap.org/soap/envelope/", true, false, true);
206 void WriteObject_Fault (System.Web.Services.Protocols.Fault ob, string element, string namesp, bool isNullable, bool needType, bool writeWrappingElem)
211 WriteNullTagLiteral(element, namesp);
215 if (writeWrappingElem) {
216 WriteStartElement (element, namesp, ob);
219 if (needType) WriteXsiType("Fault", "http://schemas.xmlsoap.org/soap/envelope/");
221 WriteElementQualifiedName ("faultcode", "", ob.@faultcode);
222 WriteElementString ("faultstring", "", ob.@faultstring);
223 WriteElementString ("faultactor", "", ob.@faultactor);
224 WriteElementLiteral (ob.@detail, "detail", "http://schemas.xmlsoap.org/soap/envelope/", false, false);
225 if (writeWrappingElem) WriteEndElement (ob);
228 protected override void InitCallbacks ()