internal override void WriteFault(XmlWriter writer, SoapException soapException)
        {
            writer.WriteStartDocument();
            writer.WriteStartElement("soap", Soap.Envelope, Soap12.Namespace);
            writer.WriteAttributeString("xmlns", "soap", null, Soap12.Namespace);
            writer.WriteAttributeString("xmlns", "xsi", null, XmlSchema.InstanceNamespace);
            writer.WriteAttributeString("xmlns", "xsd", null, XmlSchema.Namespace);
            if (ServerProtocol.ServerMethod != null)
            {
                SoapHeaderHandling.WriteHeaders(writer, ServerProtocol.ServerMethod.outHeaderSerializer, ServerProtocol.Message.Headers, ServerProtocol.ServerMethod.outHeaderMappings, SoapHeaderDirection.Fault, ServerProtocol.ServerMethod.use == SoapBindingUse.Encoded, ServerType.serviceNamespace, ServerType.serviceDefaultIsEncoded, Soap12.Namespace);
            }
            else
            {
                SoapHeaderHandling.WriteUnknownHeaders(writer, ServerProtocol.Message.Headers, Soap12.Namespace);
            }

            writer.WriteStartElement(Soap.Body, Soap12.Namespace);

            writer.WriteStartElement(Soap.Fault, Soap12.Namespace);
            writer.WriteStartElement(Soap12.FaultCode, Soap12.Namespace);
            WriteFaultCodeValue(writer, TranslateFaultCode(soapException.Code), soapException.Subcode);
            writer.WriteEndElement(); // </faultcode>
            writer.WriteElementString(Soap12.FaultReason, Soap12.Namespace, ServerProtocol.GenerateFaultString(soapException));
            // Only write an actor element if the actor was specified (it's optional for end-points)
            string actor = soapException.Actor;

            if (actor.Length > 0)
            {
                writer.WriteElementString(Soap12.FaultNode, Soap12.Namespace, actor);
            }

            string role = soapException.Role;

            if (role.Length > 0)
            {
                writer.WriteElementString(Soap12.FaultRole, Soap12.Namespace, role);
            }

            // Only write a FaultDetail element if exception is related to the body (not a header)
            if (!(soapException is SoapHeaderException))
            {
                if (soapException.Detail == null)
                {
                    writer.WriteStartElement(Soap12.FaultDetail, Soap12.Namespace);
                    writer.WriteEndElement();
                }
                else
                {
                    soapException.Detail.WriteTo(writer);
                }
            }
            writer.WriteEndElement();

            writer.WriteEndElement();
            writer.WriteEndElement();
            writer.Flush();
        }
        internal override void WriteFault(XmlWriter writer, SoapException soapException)
        {
            SoapServerMessage message = ServerProtocol.Message;

            writer.WriteStartDocument();
            writer.WriteStartElement("soap", Soap.Envelope, Soap.Namespace);
            writer.WriteAttributeString("xmlns", "soap", null, Soap.Namespace);
            writer.WriteAttributeString("xmlns", "xsi", null, XmlSchema.InstanceNamespace);
            writer.WriteAttributeString("xmlns", "xsd", null, XmlSchema.Namespace);
            if (ServerProtocol.ServerMethod != null)
            {
                SoapHeaderHandling.WriteHeaders(writer, ServerProtocol.ServerMethod.outHeaderSerializer, message.Headers, ServerProtocol.ServerMethod.outHeaderMappings, SoapHeaderDirection.Fault, ServerProtocol.ServerMethod.use == SoapBindingUse.Encoded, ServerType.serviceNamespace, ServerType.serviceDefaultIsEncoded, Soap.Namespace);
            }
            else
            {
                SoapHeaderHandling.WriteUnknownHeaders(writer, message.Headers, Soap.Namespace);
            }
            writer.WriteStartElement(Soap.Body, Soap.Namespace);

            writer.WriteStartElement(Soap.Fault, Soap.Namespace);
            writer.WriteStartElement(Soap.FaultCode, "");
            XmlQualifiedName code = TranslateFaultCode(soapException.Code);

            if (code.Namespace != null && code.Namespace.Length > 0 && writer.LookupPrefix(code.Namespace) == null)
            {
                writer.WriteAttributeString("xmlns", "q0", null, code.Namespace);
            }
            writer.WriteQualifiedName(code.Name, code.Namespace);
            writer.WriteEndElement();
            writer.WriteElementString(Soap.FaultString, "", ServerProtocol.GenerateFaultString(soapException));
            // Only write an actor element if the actor was specified (it's optional for end-points)
            string actor = soapException.Actor;

            if (actor.Length > 0)
            {
                writer.WriteElementString(Soap.FaultActor, "", actor);
            }

            // Only write a FaultDetail element if exception is related to the body (not a header)
            if (!(soapException is SoapHeaderException))
            {
                if (soapException.Detail == null)
                {
                    writer.WriteStartElement(Soap.FaultDetail, "");
                    writer.WriteEndElement();
                }
                else
                {
                    soapException.Detail.WriteTo(writer);
                }
            }
            writer.WriteEndElement();

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