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
!= 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;
120 System
.Xml
.XmlQualifiedName t
= GetXsiType();
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
)) {
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
) {
155 if (Reader
.NamespaceURI
== string.Empty
|| Reader
.NamespaceURI
== WebServiceHelper
.SoapEnvelopeNamespace
) {
156 if (Reader
.LocalName
== "faultcode" && !b0
) {
158 ob
.@faultcode
= ReadElementQualifiedName ();
159 } else if (Reader
.LocalName
== "faultstring" && !b1
) {
161 ob
.@faultstring
= Reader
.ReadElementString ();
162 } else if (Reader
.LocalName
== "detail" && !b3
) {
164 ob
.@detail
= ReadXmlNode (false);
165 } else if (Reader
.LocalName
== "faultactor" && !b2
) {
167 ob
.@faultactor
= Reader
.ReadElementString ();
177 Reader
.MoveToContent();
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
;
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
)
209 WriteNullTagLiteral(element
, namesp
);
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 ()