* Fault.cs: Moved Fault class from Methods.cd to this file. It also includes
authorLluis Sanchez <lluis@novell.com>
Fri, 27 Feb 2004 17:32:58 +0000 (17:32 -0000)
committerLluis Sanchez <lluis@novell.com>
Fri, 27 Feb 2004 17:32:58 +0000 (17:32 -0000)
  a generated serializer.
* HttpSoapWebServiceHandler.cs, WebServiceHelper.cs: Use the new static Fault serializer.
* Methods.cs: Include types declared with XmlInclude and SoapInclude to the
  reflection importer. Moved Fault and its serializer to Fault.cs
* SoapHttpClientProtocol.cs: Removed unused method.

svn path=/trunk/mcs/; revision=23542

mcs/class/System.Web.Services/System.Web.Services.Protocols/ChangeLog
mcs/class/System.Web.Services/System.Web.Services.Protocols/Fault.cs [new file with mode: 0644]
mcs/class/System.Web.Services/System.Web.Services.Protocols/HttpSoapWebServiceHandler.cs
mcs/class/System.Web.Services/System.Web.Services.Protocols/Methods.cs
mcs/class/System.Web.Services/System.Web.Services.Protocols/SoapHttpClientProtocol.cs
mcs/class/System.Web.Services/System.Web.Services.Protocols/WebServiceHelper.cs

index 00478fc19ca87a7db5bce94e76ab8471f876114c..fd2d634c42b1134e5c0327f799bdab863f0b4d9f 100644 (file)
@@ -1,3 +1,12 @@
+2004-02-27  Lluis Sanchez Gual  <lluis@ximian.com>
+
+       * Fault.cs: Moved Fault class from Methods.cd to this file. It also includes
+         a generated serializer.
+       * HttpSoapWebServiceHandler.cs, WebServiceHelper.cs: Use the new static Fault serializer.
+       * Methods.cs: Include types declared with XmlInclude and SoapInclude to the
+         reflection importer. Moved Fault and its serializer to Fault.cs
+       * SoapHttpClientProtocol.cs: Removed unused method.
+
 2004-02-12  Lluis Sanchez Gual <lluis@ximian.com>
 
        * WebServiceHelper.cs: When reading a soap request, skip empty headers. 
diff --git a/mcs/class/System.Web.Services/System.Web.Services.Protocols/Fault.cs b/mcs/class/System.Web.Services/System.Web.Services.Protocols/Fault.cs
new file mode 100644 (file)
index 0000000..b389439
--- /dev/null
@@ -0,0 +1,212 @@
+// 
+// System.Web.Services.Protocols.Fault.cs
+//
+// Author:
+//   Lluis Sanchez Gual (lluis@ximian.com)
+//
+// Copyright (C) 2004 Novell, Inc.
+//
+
+using System;
+using System.Xml;
+using System.Xml.Schema;
+using System.Xml.Serialization;
+using System.Text;
+using System.Collections;
+using System.Globalization;
+
+namespace System.Web.Services.Protocols
+{
+       internal class Fault
+       {
+               static XmlSerializer serializer;
+               
+               static Fault ()
+               {
+                       serializer = new FaultSerializer ();
+               }
+
+               public Fault () {}
+               
+               public Fault (SoapException ex) 
+               {
+                       faultcode = ex.Code;
+                       faultstring = ex.Message;
+                       faultactor = ex.Actor;
+                       detail = ex.Detail;
+               }
+
+               [XmlElement (Namespace="")]
+               public XmlQualifiedName faultcode;
+               
+               [XmlElement (Namespace="")]
+               public string faultstring;
+               
+               [XmlElement (Namespace="")]
+               public string faultactor;
+               
+               [SoapIgnore]
+               public XmlNode detail;
+               
+               public static XmlSerializer Serializer
+               {
+                       get { return serializer; }
+               }
+       }
+
+       internal class FaultSerializer : XmlSerializer 
+       {
+               protected override void Serialize (object o, XmlSerializationWriter writer)
+               {
+                       FaultWriter xsWriter = writer as FaultWriter;
+                       xsWriter.WriteRoot_Fault (o);
+               }
+               
+               protected override object Deserialize (XmlSerializationReader reader)
+               {
+                       FaultReader xsReader = reader as FaultReader;
+                       return xsReader.ReadRoot_Fault ();
+               }
+               
+               protected override XmlSerializationWriter CreateWriter ()
+               {
+                       return new FaultWriter ();
+               }
+               
+               protected override XmlSerializationReader CreateReader ()
+               {
+                       return new FaultReader ();
+               }
+       }       
+       
+       internal class FaultReader : XmlSerializationReader
+       {
+               public object ReadRoot_Fault ()
+               {
+                       Reader.MoveToContent();
+                       if (Reader.LocalName != "Fault" || Reader.NamespaceURI != "http://schemas.xmlsoap.org/soap/envelope/")
+                               throw CreateUnknownNodeException();
+                       return ReadObject_Fault (true, true);
+               }
+
+               public System.Web.Services.Protocols.Fault ReadObject_Fault (bool isNullable, bool checkType)
+               {
+                       System.Web.Services.Protocols.Fault ob = null;
+                       if (isNullable && ReadNull()) return null;
+
+                       if (checkType) 
+                       {
+                               System.Xml.XmlQualifiedName t = GetXsiType();
+                               if (t != null) 
+                               {
+                                       if (t.Name != "Fault" || t.Namespace != "http://schemas.xmlsoap.org/soap/envelope/")
+                                               throw CreateUnknownTypeException(t);
+                               }
+                       }
+
+                       ob = new System.Web.Services.Protocols.Fault ();
+
+                       Reader.MoveToElement();
+
+                       while (Reader.MoveToNextAttribute())
+                       {
+                               if (IsXmlnsAttribute (Reader.Name)) {
+                               }
+                               else {
+                                       UnknownNode (ob);
+                               }
+                       }
+
+                       Reader.MoveToElement();
+                       if (Reader.IsEmptyElement) {
+                               Reader.Skip ();
+                               return ob;
+                       }
+
+                       Reader.ReadStartElement();
+                       Reader.MoveToContent();
+
+                       bool b0=false, b1=false, b2=false, b3=false;
+
+                       while (Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
+                       {
+                               if (Reader.NodeType == System.Xml.XmlNodeType.Element) 
+                               {
+                                       if (Reader.LocalName == "faultcode" && Reader.NamespaceURI == "" && !b0) {
+                                               b0 = true;
+                                               ob.@faultcode = ReadElementQualifiedName ();
+                                       }
+                                       else if (Reader.LocalName == "faultstring" && Reader.NamespaceURI == "" && !b1) {
+                                               b1 = true;
+                                               ob.@faultstring = Reader.ReadElementString ();
+                                       }
+                                       else if (Reader.LocalName == "detail" && Reader.NamespaceURI == "http://schemas.xmlsoap.org/soap/envelope/" && !b3) {
+                                               b3 = true;
+                                               ob.@detail = ReadXmlNode (true);
+                                       }
+                                       else if (Reader.LocalName == "faultactor" && Reader.NamespaceURI == "" && !b2) {
+                                               b2 = true;
+                                               ob.@faultactor = Reader.ReadElementString ();
+                                       }
+                                       else {
+                                               UnknownNode (ob);
+                                       }
+                               }
+                               else
+                                       UnknownNode(ob);
+
+                               Reader.MoveToContent();
+                       }
+
+                       ReadEndElement();
+
+                       return ob;
+               }
+
+               protected override void InitCallbacks ()
+               {
+               }
+
+               protected override void InitIDs ()
+               {
+               }
+       }
+
+       internal class FaultWriter : XmlSerializationWriter
+       {
+               public void WriteRoot_Fault (object o)
+               {
+                       WriteStartDocument ();
+                       System.Web.Services.Protocols.Fault ob = (System.Web.Services.Protocols.Fault) o;
+                       TopLevelElement ();
+                       WriteObject_Fault (ob, "Fault", "http://schemas.xmlsoap.org/soap/envelope/", true, false, true);
+               }
+
+               void WriteObject_Fault (System.Web.Services.Protocols.Fault ob, string element, string namesp, bool isNullable, bool needType, bool writeWrappingElem)
+               {
+                       if (ob == null)
+                       {
+                               if (isNullable)
+                                       WriteNullTagLiteral(element, namesp);
+                               return;
+                       }
+
+                       if (writeWrappingElem) {
+                               WriteStartElement (element, namesp, ob);
+                       }
+
+                       if (needType) WriteXsiType("Fault", "http://schemas.xmlsoap.org/soap/envelope/");
+
+                       WriteElementQualifiedName ("faultcode", "", ob.@faultcode);
+                       WriteElementString ("faultstring", "", ob.@faultstring);
+                       WriteElementString ("faultactor", "", ob.@faultactor);
+                       WriteElementLiteral (ob.@detail, "detail", "http://schemas.xmlsoap.org/soap/envelope/", false, false);
+                       if (writeWrappingElem) WriteEndElement (ob);
+               }
+
+               protected override void InitCallbacks ()
+               {
+               }
+       }
+}
+
index dc1ba17fa5df1e1a7dfadfc22ca75aa27040ec81..b099b9817a77ae679ccce21294cc95da416a1a63 100755 (executable)
@@ -243,7 +243,7 @@ namespace System.Web.Services.Protocols
                                if (message.Exception == null)
                                        WebServiceHelper.WriteSoapMessage (xtw, _typeStubInfo, methodInfo.Use, methodInfo.ResponseSerializer, message.OutParameters, message.Headers);
                                else
-                                       WebServiceHelper.WriteSoapMessage (xtw, _typeStubInfo, SoapBindingUse.Literal, _typeStubInfo.GetFaultSerializer(), new Fault (message.Exception), null);
+                                       WebServiceHelper.WriteSoapMessage (xtw, _typeStubInfo, SoapBindingUse.Literal, Fault.Serializer, new Fault (message.Exception), null);
 
                                if (bufferResponse)
                                {
index f212db57a02398dc44461e52ce2683d14f46f209..53761a2b99c787b3f906f0639663c871ca70bcfc 100644 (file)
@@ -144,10 +144,12 @@ namespace System.Web.Services.Protocols {
                        XmlReflectionMember [] out_members = BuildResponseReflectionMembers (optional_ns);
 
                        if (Use == SoapBindingUse.Literal) {
+                               xmlImporter.IncludeTypes (source.CustomAttributeProvider);
                                InputMembersMapping = xmlImporter.ImportMembersMapping (RequestName, RequestNamespace, in_members, hasWrappingElem);
                                OutputMembersMapping = xmlImporter.ImportMembersMapping (ResponseName, ResponseNamespace, out_members, hasWrappingElem);
                        }
                        else {
+                               soapImporter.IncludeTypes (source.CustomAttributeProvider);
                                InputMembersMapping = soapImporter.ImportMembersMapping (RequestName, RequestNamespace, in_members, hasWrappingElem, writeAccessors);
                                OutputMembersMapping = soapImporter.ImportMembersMapping (ResponseName, ResponseNamespace, out_members, hasWrappingElem, writeAccessors);
                        }
@@ -276,34 +278,7 @@ namespace System.Web.Services.Protocols {
                }
        }
 
-       // FIXME: this class should be internal, but it needs to be public in
-       // order to be serialized using XmlSerializer.
-       [XmlRoot (Namespace="http://schemas.xmlsoap.org/soap/envelope/")]
-       public class Fault
-       {
-               public Fault () {}
-
-               public Fault (SoapException ex) 
-               {
-                       faultcode = ex.Code;
-                       faultstring = ex.Message;
-                       faultactor = ex.Actor;
-                       detail = ex.Detail;
-               }
 
-               [XmlElement (Namespace="")]
-               public XmlQualifiedName faultcode;
-               
-               [XmlElement (Namespace="")]
-               public string faultstring;
-               
-               [XmlElement (Namespace="")]
-               public string faultactor;
-               
-               [SoapIgnore]
-               public XmlNode detail;
-       }
-       
        //
        // Holds the metadata loaded from the type stub, as well as
        // the metadata for all the methods in the type
@@ -318,7 +293,6 @@ namespace System.Web.Services.Protocols {
                internal SoapParameterStyle      ParameterStyle;
                internal SoapServiceRoutingStyle RoutingStyle;
                internal SoapBindingUse          Use;
-               internal int                     faultSerializerId = -1;
                internal SoapExtensionRuntimeConfig[][] SoapExtensions;
                internal SoapBindingStyle SoapBindingStyle;
                internal XmlReflectionImporter  xmlImporter;
@@ -363,6 +337,9 @@ namespace System.Web.Services.Protocols {
                        
                        if (ParameterStyle == SoapParameterStyle.Default) ParameterStyle = SoapParameterStyle.Wrapped;
                        if (Use == SoapBindingUse.Default) Use = SoapBindingUse.Literal;
+                       
+                       xmlImporter.IncludeTypes (Type);
+                       soapImporter.IncludeTypes (Type);
 
                        SoapExtensions = SoapExtension.GetTypeExtensions (Type);
                }
@@ -395,21 +372,10 @@ namespace System.Web.Services.Protocols {
                        else
                                res = new SoapMethodStubInfo (parent, lmi, ats[0], xmlImporter, soapImporter);
                                
-                       if (faultSerializerId == -1)
-                       {
-                               XmlReflectionImporter ri = new XmlReflectionImporter ();
-                               XmlTypeMapping tm = ri.ImportTypeMapping (typeof(Fault));
-                               faultSerializerId = RegisterSerializer (tm);
-                       }
                        methods_byaction [res.Action] = res;
                        return res;
                }
                
-               public XmlSerializer GetFaultSerializer ()
-               {
-                       return GetSerializer (faultSerializerId);
-               }
-               
                internal void RegisterHeaderType (Type type, string serviceNamespace, SoapBindingUse use)
                {
                        Hashtable serializers = header_serializers [(int)use];
index 41611fb95de22b046593686297b1d9f27c606c7a..f12237e87b7ed2c7e845e2abfaecca234adf7002 100644 (file)
@@ -149,19 +149,6 @@ namespace System.Web.Services.Protocols {
                        return base.GetWebRequest (uri);\r
                }\r
 \r
-               //\r
-               // Just for debugging\r
-               //\r
-               void DumpStackFrames ()\r
-               {\r
-                       StackTrace st = new StackTrace ();\r
-\r
-                       for (int i = 0; i < st.FrameCount; i++){\r
-                               StackFrame sf = st.GetFrame (i);\r
-                               Console.WriteLine ("At frame: {0} {1}", i, sf.GetMethod ().Name);\r
-                       }\r
-               }\r
-\r
                WebRequest GetRequestForMessage (Uri uri, SoapClientMessage message)\r
                {\r
                        WebRequest request = GetWebRequest (uri);\r
index 80fc08bc74cd0edd280e806c710287f6d4a2f33c..4322bbfc6dda08c73d8afa39d6ccd1cfe0a1f611 100755 (executable)
@@ -96,7 +96,7 @@ namespace System.Web.Services.Protocols
                        xmlReader.MoveToContent ();
                        
                        if (xmlReader.LocalName == "Fault" && xmlReader.NamespaceURI == SoapEnvelopeNamespace)
-                               bodySerializer = typeStubInfo.GetFaultSerializer ();
+                               bodySerializer = Fault.Serializer;
 \r
                        body = bodySerializer.Deserialize (xmlReader);\r
                }