Beispiel #1
0
 public static void GetHeaderMembers(SoapHeaderCollection headers, object target, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, bool client)
 {
     if ((mappings != null) && (mappings.Length != 0))
     {
         for (int i = 0; i < mappings.Length; i++)
         {
             SoapHeaderMapping mapping = mappings[i];
             if ((mapping.direction & direction) != 0)
             {
                 object obj2 = MemberHelper.GetValue(mapping.memberInfo, target);
                 if (mapping.repeats)
                 {
                     object[] objArray = (object[])obj2;
                     if (objArray != null)
                     {
                         for (int j = 0; j < objArray.Length; j++)
                         {
                             if (objArray[j] != null)
                             {
                                 headers.Add((SoapHeader)objArray[j]);
                             }
                         }
                     }
                 }
                 else if (obj2 != null)
                 {
                     headers.Add((SoapHeader)obj2);
                 }
             }
         }
     }
 }
 internal static void GetHeaderMembers(SoapHeaderCollection headers, object target, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, bool client)
 {
     for (int i = 0; i < mappings.Length; i++)
     {
         SoapHeaderMapping mapping = mappings[i];
         if ((mapping.direction & direction) == 0)
         {
             continue;
         }
         object value = MemberHelper.GetValue(mapping.memberInfo, target);
         if (mapping.repeats)
         {
             object[] values = (object[])value;
             if (values == null)
             {
                 continue;
             }
             for (int j = 0; j < values.Length; j++)
             {
                 if (values[j] != null)
                 {
                     headers.Add((SoapHeader)values[j]);
                 }
             }
         }
         else
         {
             if (value != null)
             {
                 headers.Add((SoapHeader)value);
             }
         }
     }
 }
 public static void GetHeaderMembers(SoapHeaderCollection headers, object target, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, bool client)
 {
     if ((mappings != null) && (mappings.Length != 0))
     {
         for (int i = 0; i < mappings.Length; i++)
         {
             SoapHeaderMapping mapping = mappings[i];
             if ((mapping.direction & direction) != 0)
             {
                 object obj2 = MemberHelper.GetValue(mapping.memberInfo, target);
                 if (mapping.repeats)
                 {
                     object[] objArray = (object[]) obj2;
                     if (objArray != null)
                     {
                         for (int j = 0; j < objArray.Length; j++)
                         {
                             if (objArray[j] != null)
                             {
                                 headers.Add((SoapHeader) objArray[j]);
                             }
                         }
                     }
                 }
                 else if (obj2 != null)
                 {
                     headers.Add((SoapHeader) obj2);
                 }
             }
         }
     }
 }
Beispiel #4
0
 public SoapHeaderCollection Deserialize(XmlTextReader xmlReader)
 {
     try {
         headerSerializer.UnknownElement += new XmlElementEventHandler(OnAddUnknownHeader);
         object[] headerArray = (object[])headerSerializer.Deserialize(xmlReader);
         foreach (SoapHeader h in headerArray)
         {
             if (h != null)
             {
                 headers.Add(h);
             }
         }
         return(headers);
     } finally {
         headerSerializer.UnknownElement -= new XmlElementEventHandler(OnAddUnknownHeader);
     }
 }
        void OnUnknownElement(object sender, XmlElementEventArgs e)
        {
            if (Thread.CurrentThread.GetHashCode() != this.currentThread)
            {
                return;
            }
            if (e.Element == null)
            {
                return;
            }
            SoapUnknownHeader header = new SoapUnknownHeader();

            header.Element = e.Element;
            unknownHeaders.Add(header);
        }
        void OnUnreferencedObject(object sender, UnreferencedObjectEventArgs e)
        {
            if (Thread.CurrentThread.GetHashCode() != this.currentThread)
            {
                return;
            }
            object o = e.UnreferencedObject;

            if (o == null)
            {
                return;
            }
            if (typeof(SoapHeader).IsAssignableFrom(o.GetType()))
            {
                unreferencedHeaders.Add((SoapHeader)o);
            }
        }
 public string ReadHeaders(XmlReader reader, XmlSerializer serializer, SoapHeaderCollection headers, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, string envelopeNS, string encodingStyle, bool checkRequiredHeaders)
 {
     string headerElementName = null;
     reader.MoveToContent();
     if (!reader.IsStartElement("Header", envelopeNS))
     {
         if ((checkRequiredHeaders && (mappings != null)) && (mappings.Length > 0))
         {
             headerElementName = GetHeaderElementName(mappings[0].headerType);
         }
         return headerElementName;
     }
     if (reader.IsEmptyElement)
     {
         reader.Skip();
         return headerElementName;
     }
     this.unknownHeaders = new SoapHeaderCollection();
     this.unreferencedHeaders = new SoapHeaderCollection();
     this.currentThread = Thread.CurrentThread.GetHashCode();
     this.envelopeNS = envelopeNS;
     int depth = reader.Depth;
     reader.ReadStartElement();
     reader.MoveToContent();
     XmlDeserializationEvents events = new XmlDeserializationEvents {
         OnUnknownElement = new XmlElementEventHandler(this.OnUnknownElement),
         OnUnreferencedObject = new UnreferencedObjectEventHandler(this.OnUnreferencedObject)
     };
     TraceMethod caller = Tracing.On ? new TraceMethod(this, "ReadHeaders", new object[0]) : null;
     if (Tracing.On)
     {
         Tracing.Enter(Tracing.TraceId("TraceReadHeaders"), caller, new TraceMethod(serializer, "Deserialize", new object[] { reader, encodingStyle }));
     }
     object[] objArray = (object[]) serializer.Deserialize(reader, encodingStyle, events);
     if (Tracing.On)
     {
         Tracing.Exit(Tracing.TraceId("TraceReadHeaders"), caller);
     }
     for (int i = 0; i < objArray.Length; i++)
     {
         if (objArray[i] != null)
         {
             SoapHeader header = (SoapHeader) objArray[i];
             header.DidUnderstand = true;
             headers.Add(header);
         }
         else if (checkRequiredHeaders && (headerElementName == null))
         {
             headerElementName = GetHeaderElementName(mappings[i].headerType);
         }
     }
     this.currentThread = 0;
     this.envelopeNS = null;
     foreach (SoapHeader header2 in this.unreferencedHeaders)
     {
         headers.Add(header2);
     }
     this.unreferencedHeaders = null;
     foreach (SoapHeader header3 in this.unknownHeaders)
     {
         headers.Add(header3);
     }
     this.unknownHeaders = null;
     while ((depth < reader.Depth) && reader.Read())
     {
     }
     if (reader.NodeType == XmlNodeType.EndElement)
     {
         reader.Read();
     }
     return headerElementName;
 }
        internal void ReadHeaders(XmlReader reader, XmlSerializer serializer, SoapHeaderCollection headers, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, string envelopeNs, string encodingStyle)
        {
            reader.MoveToContent();
            if (!reader.IsStartElement(Soap.Header, envelopeNs))
            {
                return;
            }
            if (reader.IsEmptyElement)
            {
                reader.Skip(); return;
            }

            this.unknownHeaders      = new SoapHeaderCollection();
            this.unreferencedHeaders = new SoapHeaderCollection();
            // thread hash code is used to differentiate between deserializations in event callbacks
            this.currentThread = Thread.CurrentThread.GetHashCode();
            this.envelopeNs    = envelopeNs;

            XmlElementEventHandler         unknownHandler      = new XmlElementEventHandler(this.OnUnknownElement);
            UnreferencedObjectEventHandler unreferencedHandler = new UnreferencedObjectEventHandler(this.OnUnreferencedObject);

            serializer.UnknownElement     += unknownHandler;
            serializer.UnreferencedObject += unreferencedHandler;

            reader.ReadStartElement();
            reader.MoveToContent();

            // SOAP12: not using encodingStyle
            //object[] headerValues = (object[])serializer.Deserialize(reader, encodingStyle);
            object[] headerValues = (object[])serializer.Deserialize(reader);
            for (int i = 0; i < headerValues.Length; i++)
            {
                if (headerValues[i] != null)
                {
                    SoapHeader header = (SoapHeader)headerValues[i];
                    header.DidUnderstand = true;
                    headers.Add(header);
                }
            }

            serializer.UnknownElement     -= unknownHandler;
            serializer.UnreferencedObject -= unreferencedHandler;
            this.currentThread             = 0;
            this.envelopeNs = null;

            foreach (SoapHeader header in this.unreferencedHeaders)
            {
                headers.Add(header);
            }
            this.unreferencedHeaders = null;

            foreach (SoapHeader header in this.unknownHeaders)
            {
                headers.Add(header);
            }
            this.unknownHeaders = null;

            while (reader.NodeType == XmlNodeType.Whitespace)
            {
                reader.Skip();
            }

            if (reader.NodeType == XmlNodeType.None)
            {
                reader.Skip();
            }
            else
            {
                reader.ReadEndElement();
            }
        }
 public static void GetHeaderMembers(SoapHeaderCollection headers, object target, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, bool client) {
     if (mappings == null || mappings.Length == 0) return;
     for (int i = 0; i < mappings.Length; i++) {
         SoapHeaderMapping mapping = mappings[i];
         if ((mapping.direction & direction) == 0) continue;
         object value = MemberHelper.GetValue(mapping.memberInfo, target);
         if (mapping.repeats) {
             object[] values = (object[])value;
             if (values == null) continue;
             for (int j = 0; j < values.Length; j++) {
                 if (values[j] != null) headers.Add((SoapHeader)values[j]);
             }
         }
         else {
             if (value != null) headers.Add((SoapHeader)value);
         }
     }
 }
        // return first missing header name;
        public string ReadHeaders(XmlReader reader, XmlSerializer serializer, SoapHeaderCollection headers, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, string envelopeNS, string encodingStyle, bool checkRequiredHeaders) {
            string missingHeader = null;
            reader.MoveToContent();
            if (!reader.IsStartElement(Soap.Element.Header, envelopeNS)) {
                if (checkRequiredHeaders && mappings != null && mappings.Length > 0)
                    missingHeader = GetHeaderElementName(mappings[0].headerType);
                return missingHeader;
            }
            if (reader.IsEmptyElement) { reader.Skip(); return missingHeader; }

            this.unknownHeaders = new SoapHeaderCollection();
            this.unreferencedHeaders = new SoapHeaderCollection();
            // thread hash code is used to differentiate between deserializations in event callbacks
            this.currentThread = Thread.CurrentThread.GetHashCode();
            this.envelopeNS = envelopeNS;

            int depth = reader.Depth;
            reader.ReadStartElement();
            reader.MoveToContent();

            XmlDeserializationEvents events = new XmlDeserializationEvents();
            events.OnUnknownElement = new XmlElementEventHandler(this.OnUnknownElement);
            events.OnUnreferencedObject = new UnreferencedObjectEventHandler(this.OnUnreferencedObject);

            TraceMethod caller = Tracing.On ? new TraceMethod(this, "ReadHeaders") : null;
            if (Tracing.On) Tracing.Enter(Tracing.TraceId(Res.TraceReadHeaders), caller, new TraceMethod(serializer, "Deserialize", reader, encodingStyle));
            object[] headerValues = (object[])serializer.Deserialize(reader, encodingStyle, events);
            if (Tracing.On) Tracing.Exit(Tracing.TraceId(Res.TraceReadHeaders), caller);
            for (int i = 0; i < headerValues.Length; i++) {
                if (headerValues[i] != null) {
                    SoapHeader header = (SoapHeader)headerValues[i];
                    header.DidUnderstand = true;
                    headers.Add(header);
                }
                else if (checkRequiredHeaders) {
                    // run time check for R2738 A MESSAGE MUST include all soapbind:headers specified on a wsdl:input or wsdl:output of a wsdl:operationwsdl:binding that describes it. 
                    if (missingHeader == null)
                        missingHeader = GetHeaderElementName(mappings[i].headerType);
                }
            }
            this.currentThread = 0;
            this.envelopeNS = null;

            foreach (SoapHeader header in this.unreferencedHeaders) {
                headers.Add(header);
            }
            this.unreferencedHeaders = null;

            foreach (SoapHeader header in this.unknownHeaders) {
                headers.Add(header);
            }
            this.unknownHeaders = null;

            // Consume soap:Body and soap:Envelope closing tags
            while (depth < reader.Depth && reader.Read()) {
                // Nothing, just read on
            }
            // consume end tag
            if (reader.NodeType == XmlNodeType.EndElement) {
                reader.Read();
            }

            return missingHeader;
        }
Beispiel #11
0
        // return first missing header name;
        public string ReadHeaders(XmlReader reader, XmlSerializer serializer, SoapHeaderCollection headers, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, string envelopeNS, string encodingStyle, bool checkRequiredHeaders)
        {
            string missingHeader = null;

            reader.MoveToContent();
            if (!reader.IsStartElement(Soap.Element.Header, envelopeNS))
            {
                if (checkRequiredHeaders && mappings != null && mappings.Length > 0)
                {
                    missingHeader = GetHeaderElementName(mappings[0].headerType);
                }
                return(missingHeader);
            }
            if (reader.IsEmptyElement)
            {
                reader.Skip(); return(missingHeader);
            }

            this.unknownHeaders      = new SoapHeaderCollection();
            this.unreferencedHeaders = new SoapHeaderCollection();
            // thread hash code is used to differentiate between deserializations in event callbacks
            this.currentThread = Thread.CurrentThread.GetHashCode();
            this.envelopeNS    = envelopeNS;

            int depth = reader.Depth;

            reader.ReadStartElement();
            reader.MoveToContent();

            XmlDeserializationEvents events = new XmlDeserializationEvents();

            events.OnUnknownElement     = new XmlElementEventHandler(this.OnUnknownElement);
            events.OnUnreferencedObject = new UnreferencedObjectEventHandler(this.OnUnreferencedObject);

            TraceMethod caller = Tracing.On ? new TraceMethod(this, "ReadHeaders") : null;

            if (Tracing.On)
            {
                Tracing.Enter(Tracing.TraceId(Res.TraceReadHeaders), caller, new TraceMethod(serializer, "Deserialize", reader, encodingStyle));
            }
            object[] headerValues = (object[])serializer.Deserialize(reader, encodingStyle, events);
            if (Tracing.On)
            {
                Tracing.Exit(Tracing.TraceId(Res.TraceReadHeaders), caller);
            }
            for (int i = 0; i < headerValues.Length; i++)
            {
                if (headerValues[i] != null)
                {
                    SoapHeader header = (SoapHeader)headerValues[i];
                    header.DidUnderstand = true;
                    headers.Add(header);
                }
                else if (checkRequiredHeaders)
                {
                    // run time check for R2738 A MESSAGE MUST include all soapbind:headers specified on a wsdl:input or wsdl:output of a wsdl:operationwsdl:binding that describes it.
                    if (missingHeader == null)
                    {
                        missingHeader = GetHeaderElementName(mappings[i].headerType);
                    }
                }
            }
            this.currentThread = 0;
            this.envelopeNS    = null;

            foreach (SoapHeader header in this.unreferencedHeaders)
            {
                headers.Add(header);
            }
            this.unreferencedHeaders = null;

            foreach (SoapHeader header in this.unknownHeaders)
            {
                headers.Add(header);
            }
            this.unknownHeaders = null;

            // Consume soap:Body and soap:Envelope closing tags
            while (depth < reader.Depth && reader.Read())
            {
                // Nothing, just read on
            }
            // consume end tag
            if (reader.NodeType == XmlNodeType.EndElement)
            {
                reader.Read();
            }

            return(missingHeader);
        }
		static SoapHeaderCollection ReadHeaders (SoapTypeStubInfo typeStubInfo, SoapBindingUse methodUse, XmlTextReader xmlReader)
		{
			SoapHeaderCollection headers = new SoapHeaderCollection ();
			while (! (xmlReader.NodeType == XmlNodeType.Element && xmlReader.LocalName == "Body" && xmlReader.NamespaceURI == WebServiceHelper.SoapEnvelopeNamespace))
			{
				if (xmlReader.NodeType == XmlNodeType.Element && xmlReader.LocalName == "Header" 
				    && xmlReader.NamespaceURI == WebServiceHelper.SoapEnvelopeNamespace && !xmlReader.IsEmptyElement)
				{
					xmlReader.ReadStartElement ();
					xmlReader.MoveToContent ();
					
					while (xmlReader.NodeType != XmlNodeType.Element && xmlReader.NodeType != XmlNodeType.EndElement)
						xmlReader.Skip ();
						
					xmlReader.MoveToContent ();
					
					if (xmlReader.NodeType == XmlNodeType.Element) {
						XmlQualifiedName qname = new XmlQualifiedName (xmlReader.LocalName, xmlReader.NamespaceURI);
						XmlSerializer headerSerializer = typeStubInfo.GetHeaderSerializer (qname, methodUse);
						if (headerSerializer != null)
						{
							SoapHeader header = (SoapHeader) headerSerializer.Deserialize (xmlReader);
							headers.Add (header);
						}
						else
						{
							XmlDocument doc = new XmlDocument ();
							XmlElement elem = (XmlElement) doc.ReadNode (xmlReader);
							headers.Add (new SoapUnknownHeader (elem));
						}
					}
					
					while (xmlReader.NodeType != XmlNodeType.EndElement)
						xmlReader.Skip ();
						
					xmlReader.ReadEndElement ();
				}
				else
					xmlReader.Skip ();
			}
			return headers;
		}
Beispiel #13
0
        public string ReadHeaders(XmlReader reader, XmlSerializer serializer, SoapHeaderCollection headers, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, string envelopeNS, string encodingStyle, bool checkRequiredHeaders)
        {
            string headerElementName = null;

            reader.MoveToContent();
            if (!reader.IsStartElement("Header", envelopeNS))
            {
                if ((checkRequiredHeaders && (mappings != null)) && (mappings.Length > 0))
                {
                    headerElementName = GetHeaderElementName(mappings[0].headerType);
                }
                return(headerElementName);
            }
            if (reader.IsEmptyElement)
            {
                reader.Skip();
                return(headerElementName);
            }
            this.unknownHeaders      = new SoapHeaderCollection();
            this.unreferencedHeaders = new SoapHeaderCollection();
            this.currentThread       = Thread.CurrentThread.GetHashCode();
            this.envelopeNS          = envelopeNS;
            int depth = reader.Depth;

            reader.ReadStartElement();
            reader.MoveToContent();
            XmlDeserializationEvents events = new XmlDeserializationEvents {
                OnUnknownElement     = new XmlElementEventHandler(this.OnUnknownElement),
                OnUnreferencedObject = new UnreferencedObjectEventHandler(this.OnUnreferencedObject)
            };
            TraceMethod caller = Tracing.On ? new TraceMethod(this, "ReadHeaders", new object[0]) : null;

            if (Tracing.On)
            {
                Tracing.Enter(Tracing.TraceId("TraceReadHeaders"), caller, new TraceMethod(serializer, "Deserialize", new object[] { reader, encodingStyle }));
            }
            object[] objArray = (object[])serializer.Deserialize(reader, encodingStyle, events);
            if (Tracing.On)
            {
                Tracing.Exit(Tracing.TraceId("TraceReadHeaders"), caller);
            }
            for (int i = 0; i < objArray.Length; i++)
            {
                if (objArray[i] != null)
                {
                    SoapHeader header = (SoapHeader)objArray[i];
                    header.DidUnderstand = true;
                    headers.Add(header);
                }
                else if (checkRequiredHeaders && (headerElementName == null))
                {
                    headerElementName = GetHeaderElementName(mappings[i].headerType);
                }
            }
            this.currentThread = 0;
            this.envelopeNS    = null;
            foreach (SoapHeader header2 in this.unreferencedHeaders)
            {
                headers.Add(header2);
            }
            this.unreferencedHeaders = null;
            foreach (SoapHeader header3 in this.unknownHeaders)
            {
                headers.Add(header3);
            }
            this.unknownHeaders = null;
            while ((depth < reader.Depth) && reader.Read())
            {
            }
            if (reader.NodeType == XmlNodeType.EndElement)
            {
                reader.Read();
            }
            return(headerElementName);
        }