Example #1
0
        internal static void WriteUnknownHeaders(XmlWriter writer, SoapHeaderCollection headers, string envelopeNs)
        {
            bool first = true;

            foreach (SoapHeader header in headers)
            {
                SoapUnknownHeader unknown = header as SoapUnknownHeader;
                if (unknown != null)
                {
                    if (first)
                    {
                        writer.WriteStartElement(Soap.Header, envelopeNs);
                        first = false;
                    }
                    if (unknown.Element != null)
                    {
                        unknown.Element.WriteTo(writer);
                    }
                }
            }
            if (!first)
            {
                writer.WriteEndElement(); // </soap:Header>
            }
        }
Example #2
0
        public static void WriteUnknownHeaders(XmlWriter writer, SoapHeaderCollection headers, string envelopeNS)
        {
            bool flag = true;

            foreach (SoapHeader header in headers)
            {
                SoapUnknownHeader header2 = header as SoapUnknownHeader;
                if (header2 != null)
                {
                    if (flag)
                    {
                        writer.WriteStartElement("Header", envelopeNS);
                        flag = false;
                    }
                    if (header2.Element != null)
                    {
                        header2.Element.WriteTo(writer);
                    }
                }
            }
            if (!flag)
            {
                writer.WriteEndElement();
            }
        }
Example #3
0
        internal void SetHeaderValue(object ob, SoapHeader header)
        {
            object value = header;

            if (Custom && HeaderType.IsArray)
            {
                SoapUnknownHeader   uheader = header as SoapUnknownHeader;
                SoapUnknownHeader[] array   = (SoapUnknownHeader[])GetHeaderValue(ob);
                if (array == null || array.Length == 0)
                {
                    value = new SoapUnknownHeader[] { uheader };
                }
                else
                {
                    SoapUnknownHeader[] newArray = new SoapUnknownHeader [array.Length + 1];
                    Array.Copy(array, newArray, array.Length);
                    newArray [array.Length] = uheader;
                    value = newArray;
                }
            }

            if (member is PropertyInfo)
            {
                ((PropertyInfo)member).SetValue(ob, value, null);
            }
            else
            {
                ((FieldInfo)member).SetValue(ob, value);
            }
        }
Example #4
0
 private void OnUnknownElement(object sender, XmlElementEventArgs e)
 {
     if ((Thread.CurrentThread.GetHashCode() == this.currentThread) && (e.Element != null))
     {
         SoapUnknownHeader header = new SoapUnknownHeader {
             Element = e.Element
         };
         this.unknownHeaders.Add(header);
     }
 }
Example #5
0
        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);
        }
Example #6
0
        internal SoapUnknownHeader CreateUpgradeHeader()
        {
            XmlDocument doc            = new XmlDocument();
            XmlElement  upgradeElement = doc.CreateElement("upg", Soap12.Upgrade, Soap12.UpgradeNamespace);

            if (IsSupported(ProtocolsEnum.HttpSoap))
            {
                upgradeElement.AppendChild(CreateUpgradeEnvelope(doc, "soap", Soap.Namespace));
            }
            if (IsSupported(ProtocolsEnum.HttpSoap12))
            {
                upgradeElement.AppendChild(CreateUpgradeEnvelope(doc, "soap12", Soap12.Namespace));
            }

            SoapUnknownHeader upgradeHeader = new SoapUnknownHeader();

            upgradeHeader.Element = upgradeElement;
            return(upgradeHeader);
        }
Example #7
0
		internal void SetHeaderValue (object ob, SoapHeader header)
		{
			object value = header;
			if (Custom && HeaderType.IsArray)
			{
				SoapUnknownHeader uheader = header as SoapUnknownHeader;
				SoapUnknownHeader[] array = (SoapUnknownHeader[]) GetHeaderValue (ob);
				if (array == null || array.Length == 0) {
					value = new SoapUnknownHeader[] { uheader };
				}
				else {
					SoapUnknownHeader[] newArray = new SoapUnknownHeader [array.Length+1];
					Array.Copy (array, newArray, array.Length);
					newArray [array.Length] = uheader;
					value = newArray;
				}
			}
			
			if (member is PropertyInfo)
				((PropertyInfo) member).SetValue (ob, value, null);
			else
				((FieldInfo) member).SetValue (ob, value);
		}
 private void OnUnknownElement(object sender, XmlElementEventArgs e)
 {
     if ((Thread.CurrentThread.GetHashCode() == this.currentThread) && (e.Element != null))
     {
         SoapUnknownHeader header = new SoapUnknownHeader {
             Element = e.Element
         };
         this.unknownHeaders.Add(header);
     }
 }
Example #9
0
        internal static void WriteHeaders(XmlWriter writer, XmlSerializer serializer, SoapHeaderCollection headers, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, bool isEncoded, string defaultNs, bool serviceDefaultIsEncoded, string envelopeNs)
        {
            if (headers.Count == 0)
            {
                return;
            }
            if (isEncoded && writer is XmlSpecialTextWriter)
            {
                ((XmlSpecialTextWriter)writer).EncodeIds = true;
            }
            writer.WriteStartElement(Soap.Header, envelopeNs);
            // SOAP12: always soap 1.1, not using encodingStyle;
            //SoapProtocolVersion version;
            SoapProtocolVersion version = SoapProtocolVersion.Soap11;
            // SOAP12: not using encodingStyle

            /*string encodingStyle;
             * if (envelopeNs == Soap12.Namespace) {
             *  version = SoapProtocolVersion.Soap12;
             *  encodingStyle = Soap12.Encoding;
             * }
             * else {
             *  version = SoapProtocolVersion.Soap11;
             *  encodingStyle = Soap.Encoding;
             * }*/

            int       unknownHeaderCount = 0;
            ArrayList otherHeaders       = new ArrayList();

            SoapHeader[] headerArray = new SoapHeader[mappings.Length];
            bool[]       headerSet   = new bool[headerArray.Length];
            for (int i = 0; i < headers.Count; i++)
            {
                SoapHeader header = headers[i];
                if (header == null)
                {
                    continue;
                }
                int headerPosition;
                header.version = version;
                if (header is SoapUnknownHeader)
                {
                    otherHeaders.Add(header);
                    unknownHeaderCount++;
                }
                else if ((headerPosition = FindMapping(mappings, header, direction)) >= 0 && !headerSet[headerPosition])
                {
                    headerArray[headerPosition] = header;
                    headerSet[headerPosition]   = true;
                }
                else
                {
                    otherHeaders.Add(header);
                }
            }
            int otherHeaderCount = otherHeaders.Count - unknownHeaderCount;

            if (isEncoded && otherHeaderCount > 0)
            {
                SoapHeader[] newHeaderArray = new SoapHeader[mappings.Length + otherHeaderCount];
                headerArray.CopyTo(newHeaderArray, 0);

                // fill in the non-statically known headers (otherHeaders) starting after the statically-known ones
                int count = mappings.Length;
                for (int i = 0; i < otherHeaders.Count; i++)
                {
                    if (!(otherHeaders[i] is SoapUnknownHeader))
                    {
                        newHeaderArray[count++] = (SoapHeader)otherHeaders[i];
                    }
                }

                headerArray = newHeaderArray;
            }

            // SOAP12: not using encodingStyle
            //serializer.Serialize(writer, headerArray, null, isEncoded ? encodingStyle : null);
            serializer.Serialize(writer, headerArray, null);

            foreach (SoapHeader header in otherHeaders)
            {
                if (header is SoapUnknownHeader)
                {
                    SoapUnknownHeader unknown = (SoapUnknownHeader)header;
                    if (unknown.Element != null)
                    {
                        unknown.Element.WriteTo(writer);
                    }
                }
                else if (!isEncoded)   // encoded headers already appended to members mapping
                {
                    string ns = SoapReflector.GetLiteralNamespace(defaultNs, serviceDefaultIsEncoded);
                    new XmlSerializer(header.GetType(), ns).Serialize(writer, header);
                }
            }

            // reset the soap version
            for (int i = 0; i < headers.Count; i++)
            {
                SoapHeader header = headers[i];
                if (header != null)
                {
                    header.version = SoapProtocolVersion.Default;
                }
            }

            writer.WriteEndElement();
            writer.Flush();

            if (isEncoded && writer is XmlSpecialTextWriter)
            {
                ((XmlSpecialTextWriter)writer).EncodeIds = false;
            }
        }
        internal SoapUnknownHeader CreateUpgradeHeader() {
            XmlDocument doc = new XmlDocument();
            XmlElement upgradeElement = doc.CreateElement(Soap12.Prefix, Soap12.Element.Upgrade, Soap12.Namespace);
            if (IsSupported(WebServiceProtocols.HttpSoap))
                upgradeElement.AppendChild(CreateUpgradeEnvelope(doc, Soap.Prefix, Soap.Namespace));
            if (IsSupported(WebServiceProtocols.HttpSoap12))
                upgradeElement.AppendChild(CreateUpgradeEnvelope(doc, Soap12.Prefix, Soap12.Namespace));

            SoapUnknownHeader upgradeHeader = new SoapUnknownHeader();
            upgradeHeader.Element = upgradeElement;
            return upgradeHeader;
        }
Example #11
0
 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);
 }
Example #12
0
        internal override bool WriteException(Exception e, Stream outputStream)
        {
            SoapException exception;

            if (this.message == null)
            {
                return(false);
            }
            this.message.Headers.Clear();
            if ((this.serverMethod != null) && (this.Target != null))
            {
                SoapHeaderHandling.GetHeaderMembers(this.message.Headers, this.Target, this.serverMethod.outHeaderMappings, SoapHeaderDirection.Fault, false);
            }
            if (e is SoapException)
            {
                exception = (SoapException)e;
            }
            else if (((this.serverMethod != null) && this.serverMethod.rpc) && ((this.helper.Version == SoapProtocolVersion.Soap12) && (e is ArgumentException)))
            {
                exception = SoapException.Create(this.Version, System.Web.Services.Res.GetString("WebRequestUnableToProcess"), new XmlQualifiedName("Client", "http://schemas.xmlsoap.org/soap/envelope/"), null, null, null, new SoapFaultSubCode(Soap12FaultCodes.RpcBadArgumentsFaultCode), e);
            }
            else
            {
                exception = SoapException.Create(this.Version, System.Web.Services.Res.GetString("WebRequestUnableToProcess"), new XmlQualifiedName("Server", "http://schemas.xmlsoap.org/soap/envelope/"), e);
            }
            if (SoapException.IsVersionMismatchFaultCode(exception.Code) && this.IsSupported(WebServiceProtocols.HttpSoap12))
            {
                SoapUnknownHeader header = this.CreateUpgradeHeader();
                if (header != null)
                {
                    this.Message.Headers.Add(header);
                }
            }
            base.Response.ClearHeaders();
            base.Response.Clear();
            HttpStatusCode      statusCode      = this.helper.SetResponseErrorCode(base.Response, exception);
            bool                flag            = false;
            SoapExtensionStream extensionStream = new SoapExtensionStream();

            if (this.message.allExtensions != null)
            {
                this.message.SetExtensionStream(extensionStream);
            }
            try
            {
                this.message.InitExtensionStreamChain(this.message.allExtensions);
            }
            catch (Exception exception2)
            {
                if (((exception2 is ThreadAbortException) || (exception2 is StackOverflowException)) || (exception2 is OutOfMemoryException))
                {
                    throw;
                }
                if (Tracing.On)
                {
                    Tracing.ExceptionCatch(TraceEventType.Warning, this, "WriteException", exception2);
                }
                flag = true;
            }
            this.message.SetStage(SoapMessageStage.BeforeSerialize);
            this.message.ContentType = ContentType.Compose(this.helper.HttpContentType, Encoding.UTF8);
            this.message.Exception   = exception;
            if (!flag)
            {
                try
                {
                    this.message.RunExtensions(this.message.allExtensions, false);
                }
                catch (Exception exception3)
                {
                    if (((exception3 is ThreadAbortException) || (exception3 is StackOverflowException)) || (exception3 is OutOfMemoryException))
                    {
                        throw;
                    }
                    if (Tracing.On)
                    {
                        Tracing.ExceptionCatch(TraceEventType.Warning, this, "WriteException", exception3);
                    }
                    flag = true;
                }
            }
            this.message.SetStream(outputStream);
            base.Response.ContentType = this.message.ContentType;
            if ((this.message.ContentEncoding != null) && (this.message.ContentEncoding.Length > 0))
            {
                base.Response.AppendHeader("Content-Encoding", this.message.ContentEncoding);
            }
            XmlWriter writerForMessage = this.GetWriterForMessage(this.message, 0x200);

            if (writerForMessage == null)
            {
                throw new InvalidOperationException(System.Web.Services.Res.GetString("WebNullWriterForMessage"));
            }
            this.helper.WriteFault(writerForMessage, this.message.Exception, statusCode);
            if (!flag)
            {
                SoapException exception4 = null;
                try
                {
                    this.message.SetStage(SoapMessageStage.AfterSerialize);
                    this.message.RunExtensions(this.message.allExtensions, false);
                }
                catch (Exception exception5)
                {
                    if (((exception5 is ThreadAbortException) || (exception5 is StackOverflowException)) || (exception5 is OutOfMemoryException))
                    {
                        throw;
                    }
                    if (Tracing.On)
                    {
                        Tracing.ExceptionCatch(TraceEventType.Warning, this, "WriteException", exception5);
                    }
                    if (!extensionStream.HasWritten)
                    {
                        exception4 = SoapException.Create(this.Version, System.Web.Services.Res.GetString("WebExtensionError"), new XmlQualifiedName("Server", "http://schemas.xmlsoap.org/soap/envelope/"), exception5);
                    }
                }
                if (exception4 != null)
                {
                    base.Response.ContentType = ContentType.Compose("text/plain", Encoding.UTF8);
                    StreamWriter writer2 = new StreamWriter(outputStream, new UTF8Encoding(false));
                    writer2.WriteLine(base.GenerateFaultString(this.message.Exception));
                    writer2.Flush();
                }
            }
            return(true);
        }
Example #13
0
        internal override bool WriteException(Exception e, Stream outputStream)
        {
            if (message == null)
            {
                return(false);
            }

            message.Headers.Clear();
            if (serverMethod != null)
            {
                SoapHeaderHandling.GetHeaderMembers(message.Headers, this.Target, serverMethod.outHeaderMappings, SoapHeaderDirection.Fault, false);
            }

            SoapException soapException;

            if (e is SoapException)
            {
                soapException = (SoapException)e;
            }
            else if (serverMethod != null && serverMethod.rpc && helper.Version == SoapProtocolVersion.Soap12 && e is ArgumentException)
            {
                // special case to handle soap 1.2 rpc "BadArguments" fault
                soapException = new SoapException(Res.GetString(Res.WebRequestUnableToProcess), new XmlQualifiedName(Soap.ClientCode, Soap.Namespace), null, null, null, new SoapFaultSubcode(Soap12FaultCodes.RpcBadArgumentsFaultCode), e);
            }
            else
            {
                soapException = new SoapException(Res.GetString(Res.WebRequestUnableToProcess), new XmlQualifiedName(Soap.ServerCode, Soap.Namespace), e);
            }

            if (SoapException.IsVersionMismatchFaultCode(soapException.Code))
            {
                if (IsSupported(ProtocolsEnum.HttpSoap12))
                {
                    SoapUnknownHeader unknownHeader = CreateUpgradeHeader();
                    if (unknownHeader != null)
                    {
                        Message.Headers.Add(unknownHeader);
                    }
                }
            }

            Response.ClearHeaders();
            Response.Clear();
            helper.SetResponseErrorCode(Response, soapException);

            bool disableExtensions = false;

            if (message.allExtensions != null)
            {
                message.SetExtensionStream(new SoapExtensionStream());
            }

            try {
                message.InitExtensionStreamChain(message.allExtensions);
            }
            catch (Exception) {
                disableExtensions = true;
            }
            message.SetStage(SoapMessageStage.BeforeSerialize);
            message.ContentType = ContentType.Compose(helper.HttpContentType, Encoding.UTF8);
            message.SetException(soapException);
            if (!disableExtensions)
            {
                try {
                    message.RunExtensions(message.allExtensions);
                }
                catch (Exception) {
                    disableExtensions = true;
                }
            }
            message.SetStream(outputStream);
            Response.ContentType = message.ContentType;
            if (message.ContentEncoding != null && message.ContentEncoding.Length > 0)
            {
                Response.AppendHeader(ContentType.ContentEncoding, message.ContentEncoding);
            }

            bool          isEncoded = serverMethod != null && serverMethod.use == SoapBindingUse.Encoded;
            StreamWriter  sw        = new StreamWriter(message.Stream, new UTF8Encoding(false), 128);
            XmlTextWriter writer    = isEncoded && message.Headers.Count > 0 ? new XmlSpecialTextWriter(sw, helper.Version) : new XmlTextWriter(sw);

            writer.Formatting  = Formatting.Indented; // CONSIDER, don't format to save space
            writer.Indentation = 2;                   // CONSIDER, don't indent to save space

            helper.WriteFault(writer, soapException);

            if (!disableExtensions)
            {
                try {
                    message.SetStage(SoapMessageStage.AfterSerialize);
                    message.RunExtensions(message.allExtensions);
                }
                catch (Exception) {
                    // it's too late to do anything about this -- we've already written to the stream
                }
            }
            return(true);
        }
Example #14
0
        public static void WriteHeaders(XmlWriter writer, XmlSerializer serializer, SoapHeaderCollection headers, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, bool isEncoded, string defaultNS, bool serviceDefaultIsEncoded, string envelopeNS)
        {
            if (headers.Count == 0)
            {
                return;
            }
            writer.WriteStartElement(Soap.Element.Header, envelopeNS);
            SoapProtocolVersion version;
            string encodingStyle;

            if (envelopeNS == Soap12.Namespace)
            {
                version       = SoapProtocolVersion.Soap12;
                encodingStyle = Soap12.Encoding;
            }
            else
            {
                version       = SoapProtocolVersion.Soap11;
                encodingStyle = Soap.Encoding;
            }

            int       unknownHeaderCount = 0;
            ArrayList otherHeaders       = new ArrayList();

            SoapHeader[] headerArray = new SoapHeader[mappings.Length];
            bool[]       headerSet   = new bool[headerArray.Length];
            for (int i = 0; i < headers.Count; i++)
            {
                SoapHeader header = headers[i];
                if (header == null)
                {
                    continue;
                }
                int headerPosition;
                header.version = version;
                if (header is SoapUnknownHeader)
                {
                    otherHeaders.Add(header);
                    unknownHeaderCount++;
                }
                else if ((headerPosition = FindMapping(mappings, header, direction)) >= 0 && !headerSet[headerPosition])
                {
                    headerArray[headerPosition] = header;
                    headerSet[headerPosition]   = true;
                }
                else
                {
                    otherHeaders.Add(header);
                }
            }
            int otherHeaderCount = otherHeaders.Count - unknownHeaderCount;

            if (isEncoded && otherHeaderCount > 0)
            {
                SoapHeader[] newHeaderArray = new SoapHeader[mappings.Length + otherHeaderCount];
                headerArray.CopyTo(newHeaderArray, 0);

                // fill in the non-statically known headers (otherHeaders) starting after the statically-known ones
                int count = mappings.Length;
                for (int i = 0; i < otherHeaders.Count; i++)
                {
                    if (!(otherHeaders[i] is SoapUnknownHeader))
                    {
                        newHeaderArray[count++] = (SoapHeader)otherHeaders[i];
                    }
                }

                headerArray = newHeaderArray;
            }

            TraceMethod caller = Tracing.On ? new TraceMethod(typeof(SoapHeaderHandling), "WriteHeaders") : null;

            if (Tracing.On)
            {
                Tracing.Enter(Tracing.TraceId(Res.TraceWriteHeaders), caller, new TraceMethod(serializer, "Serialize", writer, headerArray, null, isEncoded ? encodingStyle : null, "h_"));
            }
            serializer.Serialize(writer, headerArray, null, isEncoded ? encodingStyle : null, "h_");
            if (Tracing.On)
            {
                Tracing.Exit(Tracing.TraceId(Res.TraceWriteHeaders), caller);
            }

            foreach (SoapHeader header in otherHeaders)
            {
                if (header is SoapUnknownHeader)
                {
                    SoapUnknownHeader unknown = (SoapUnknownHeader)header;
                    if (unknown.Element != null)
                    {
                        unknown.Element.WriteTo(writer);
                    }
                }
                else if (!isEncoded)   // encoded headers already appended to members mapping
                {
                    string        ns = SoapReflector.GetLiteralNamespace(defaultNS, serviceDefaultIsEncoded);
                    XmlSerializer headerSerializer = new XmlSerializer(header.GetType(), ns);

                    if (Tracing.On)
                    {
                        Tracing.Enter(Tracing.TraceId(Res.TraceWriteHeaders), caller, new TraceMethod(headerSerializer, "Serialize", writer, header));
                    }
                    headerSerializer.Serialize(writer, header);
                    if (Tracing.On)
                    {
                        Tracing.Exit(Tracing.TraceId(Res.TraceWriteHeaders), caller);
                    }
                }
            }

            // reset the soap version
            for (int i = 0; i < headers.Count; i++)
            {
                SoapHeader header = headers[i];
                if (header != null)
                {
                    header.version = SoapProtocolVersion.Default;
                }
            }

            writer.WriteEndElement();
            writer.Flush();
        }
Example #15
0
 public static void WriteHeaders(XmlWriter writer, XmlSerializer serializer, SoapHeaderCollection headers, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, bool isEncoded, string defaultNS, bool serviceDefaultIsEncoded, string envelopeNS)
 {
     if (headers.Count != 0)
     {
         SoapProtocolVersion version;
         string str;
         writer.WriteStartElement("Header", envelopeNS);
         if (envelopeNS == "http://www.w3.org/2003/05/soap-envelope")
         {
             version = SoapProtocolVersion.Soap12;
             str     = "http://www.w3.org/2003/05/soap-encoding";
         }
         else
         {
             version = SoapProtocolVersion.Soap11;
             str     = "http://schemas.xmlsoap.org/soap/encoding/";
         }
         int          num       = 0;
         ArrayList    list      = new ArrayList();
         SoapHeader[] o         = new SoapHeader[mappings.Length];
         bool[]       flagArray = new bool[o.Length];
         for (int i = 0; i < headers.Count; i++)
         {
             SoapHeader header = headers[i];
             if (header != null)
             {
                 header.version = version;
                 if (header is SoapUnknownHeader)
                 {
                     list.Add(header);
                     num++;
                 }
                 else
                 {
                     int num3;
                     if (((num3 = FindMapping(mappings, header, direction)) >= 0) && !flagArray[num3])
                     {
                         o[num3]         = header;
                         flagArray[num3] = true;
                     }
                     else
                     {
                         list.Add(header);
                     }
                 }
             }
         }
         int num4 = list.Count - num;
         if (isEncoded && (num4 > 0))
         {
             SoapHeader[] array = new SoapHeader[mappings.Length + num4];
             o.CopyTo(array, 0);
             int length = mappings.Length;
             for (int k = 0; k < list.Count; k++)
             {
                 if (!(list[k] is SoapUnknownHeader))
                 {
                     array[length++] = (SoapHeader)list[k];
                 }
             }
             o = array;
         }
         TraceMethod caller = Tracing.On ? new TraceMethod(typeof(SoapHeaderHandling), "WriteHeaders", new object[0]) : null;
         if (Tracing.On)
         {
             object[] args = new object[5];
             args[0] = writer;
             args[1] = o;
             args[3] = isEncoded ? str : null;
             args[4] = "h_";
             Tracing.Enter(Tracing.TraceId("TraceWriteHeaders"), caller, new TraceMethod(serializer, "Serialize", args));
         }
         serializer.Serialize(writer, o, null, isEncoded ? str : null, "h_");
         if (Tracing.On)
         {
             Tracing.Exit(Tracing.TraceId("TraceWriteHeaders"), caller);
         }
         foreach (SoapHeader header2 in list)
         {
             if (header2 is SoapUnknownHeader)
             {
                 SoapUnknownHeader header3 = (SoapUnknownHeader)header2;
                 if (header3.Element != null)
                 {
                     header3.Element.WriteTo(writer);
                 }
             }
             else if (!isEncoded)
             {
                 string        literalNamespace = SoapReflector.GetLiteralNamespace(defaultNS, serviceDefaultIsEncoded);
                 XmlSerializer target           = new XmlSerializer(header2.GetType(), literalNamespace);
                 if (Tracing.On)
                 {
                     Tracing.Enter(Tracing.TraceId("TraceWriteHeaders"), caller, new TraceMethod(target, "Serialize", new object[] { writer, header2 }));
                 }
                 target.Serialize(writer, header2);
                 if (Tracing.On)
                 {
                     Tracing.Exit(Tracing.TraceId("TraceWriteHeaders"), caller);
                 }
             }
         }
         for (int j = 0; j < headers.Count; j++)
         {
             SoapHeader header4 = headers[j];
             if (header4 != null)
             {
                 header4.version = SoapProtocolVersion.Default;
             }
         }
         writer.WriteEndElement();
         writer.Flush();
     }
 }