public override void WriteObjectContent(XmlDictionaryWriter writer, object graph)
        {
            if (this.isCustomSerialization)
            {
                DataContractJsonSerializer ser = new DataContractJsonSerializer(this.type);

                using (MemoryStream ms = new MemoryStream())
                {
                    if (m_IsCompress)
                    {
                        using (DeflateStream ds = new DeflateStream(ms, CompressionMode.Compress))
                        {
                            ser.WriteObject(ds, graph);
                            ds.Flush();
                            ds.Close();
                        }
                    }
                    else
                    {
                        ser.WriteObject(ms, graph);
                    }

                    byte[] compressed = ms.ToArray();

                    if (!m_IsCompress)
                    {
                        switch (m_ContentType)
                        {
                            case SerializeContentTypes.String:
                                string value = Encoding.UTF8.GetString(compressed);
                                writer.WriteString(value);
                                break;
                            case SerializeContentTypes.BinHex:
                                writer.WriteBinHex(compressed, 0, compressed.Length);
                                break;
                        }
                    }
                    else
                    {
                        writer.WriteBinHex(compressed, 0, compressed.Length);
                    }
                }
            }
            else
            {
                this.fallbackSerializer.WriteObjectContent(writer, graph);
            }
        }
예제 #2
0
 public override void WriteBinHex(byte[] buffer, int index, int count)
 {
     writer.WriteBinHex(buffer, index, count);
 }
            public override void WriteContent(XmlDictionaryWriter writer, SecurityKeyIdentifierClause clause)
            {
                writer.WriteStartElement(XD.SecurityJan2004Dictionary.Prefix.Value, XD.SecurityJan2004Dictionary.KeyIdentifier, XD.SecurityJan2004Dictionary.Namespace);
                writer.WriteAttributeString(XD.SecurityJan2004Dictionary.ValueType, null, this.ValueTypeUri);
                if (this.tokenSerializer.EmitBspRequiredAttributes)
                {
                    writer.WriteAttributeString(XD.SecurityJan2004Dictionary.EncodingType, null, this.DefaultEncodingType);
                }
                string defaultEncodingType = this.DefaultEncodingType;
                byte[] buffer = (clause as BinaryKeyIdentifierClause).GetBuffer();
                switch (defaultEncodingType)
                {
                    case "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary":
                        writer.WriteBase64(buffer, 0, buffer.Length);
                        break;

                    case "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#HexBinary":
                        writer.WriteBinHex(buffer, 0, buffer.Length);
                        break;

                    case "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Text":
                        writer.WriteString(new UTF8Encoding().GetString(buffer, 0, buffer.Length));
                        break;
                }
                writer.WriteEndElement();
            }
            public override void WriteContent(XmlDictionaryWriter writer, SecurityKeyIdentifierClause clause)
            {
                writer.WriteStartElement(XD.SecurityJan2004Dictionary.Prefix.Value, XD.SecurityJan2004Dictionary.KeyIdentifier, XD.SecurityJan2004Dictionary.Namespace);
                writer.WriteAttributeString(XD.SecurityJan2004Dictionary.ValueType, null, ValueTypeUri);
                KerberosTicketHashKeyIdentifierClause binaryClause = clause as KerberosTicketHashKeyIdentifierClause;
                if (this.EmitBspRequiredAttributes)
                {
                    // Emit the encodingType attribute.
                    writer.WriteAttributeString(XD.SecurityJan2004Dictionary.EncodingType, null, DefaultEncodingType);
                }
                string encoding = DefaultEncodingType;

                byte[] keyIdentifier = binaryClause.GetBuffer();
                if (encoding == EncodingTypeValueBase64Binary)
                {
                    writer.WriteBase64(keyIdentifier, 0, keyIdentifier.Length);
                }
                else if (encoding == EncodingTypeValueHexBinary)
                {
                    writer.WriteBinHex(keyIdentifier, 0, keyIdentifier.Length);
                }
                else if (encoding == EncodingTypeValueText)
                {
                    writer.WriteString(new UTF8Encoding().GetString(keyIdentifier, 0, keyIdentifier.Length));
                }
                writer.WriteEndElement();
            }