WSSecurityTokenSerializer Class

 

The class used for serializing and deserializing security tokens, security key identifiers, and security key identifier clauses defined in the WS-Security, WS-Trust, and WS-SecureConversation security specifications.

Namespace:   System.ServiceModel.Security
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

System.Object
  System.IdentityModel.Selectors.SecurityTokenSerializer
    System.ServiceModel.Security.WSSecurityTokenSerializer

public class WSSecurityTokenSerializer : SecurityTokenSerializer

NameDescription
System_CAPS_pubmethodWSSecurityTokenSerializer()

Initializes a new instance of the WSSecurityTokenSerializer class.

System_CAPS_pubmethodWSSecurityTokenSerializer(Boolean)

Initializes a new instance of the WSSecurityTokenSerializer class.

System_CAPS_pubmethodWSSecurityTokenSerializer(SecurityVersion)

Initializes a new instance of the WSSecurityTokenSerializer class.

System_CAPS_pubmethodWSSecurityTokenSerializer(SecurityVersion, Boolean)

Initializes a new instance of the WSSecurityTokenSerializer class.

System_CAPS_pubmethodWSSecurityTokenSerializer(SecurityVersion, Boolean, SamlSerializer)

Initializes a new instance of the WSSecurityTokenSerializer class.

System_CAPS_pubmethodWSSecurityTokenSerializer(SecurityVersion, Boolean, SamlSerializer, SecurityStateEncoder, IEnumerable<Type>)

Initializes a new instance of the WSSecurityTokenSerializer class.

System_CAPS_pubmethodWSSecurityTokenSerializer(SecurityVersion, Boolean, SamlSerializer, SecurityStateEncoder, IEnumerable<Type>, Int32, Int32, Int32)

Initializes a new instance of the WSSecurityTokenSerializer class.

System_CAPS_pubmethodWSSecurityTokenSerializer(SecurityVersion, TrustVersion, SecureConversationVersion, Boolean, SamlSerializer, SecurityStateEncoder, IEnumerable<Type>)

Initializes a new instance of the WSSecurityTokenSerializer class.

System_CAPS_pubmethodWSSecurityTokenSerializer(SecurityVersion, TrustVersion, SecureConversationVersion, Boolean, SamlSerializer, SecurityStateEncoder, IEnumerable<Type>, Int32, Int32, Int32)

Initializes a new instance of the WSSecurityTokenSerializer class.

NameDescription
System_CAPS_pubpropertySystem_CAPS_staticDefaultInstance

Gets a default instance of this class.

System_CAPS_pubpropertyEmitBspRequiredAttributes

Gets a value that indicates whether to emit BSP required attributes.

System_CAPS_pubpropertyMaximumKeyDerivationLabelLength

Gets the maximum key derivation label length.

System_CAPS_pubpropertyMaximumKeyDerivationNonceLength

Gets the maximum key derivation nonce length.

System_CAPS_pubpropertyMaximumKeyDerivationOffset

Gets the maximum key derivation offset.

System_CAPS_pubpropertySecurityVersion

Gets the security version.

NameDescription
System_CAPS_pubmethodCanReadKeyIdentifier(XmlReader)

Determines whether this serializer can read the <KeyIdentifier> element referred to by the specified XML reader. (Inherited from SecurityTokenSerializer.)

System_CAPS_pubmethodCanReadKeyIdentifierClause(XmlReader)

Determines whether this serializer can read a clause in a <KeyIdentifier> element referred to by the specified XML reader. (Inherited from SecurityTokenSerializer.)

System_CAPS_protmethodCanReadKeyIdentifierClauseCore(XmlReader)

Gets a value that indicates whether the key identifier clause core can be read using the specified reader. (Overrides SecurityTokenSerializer.CanReadKeyIdentifierClauseCore(XmlReader).)

System_CAPS_protmethodCanReadKeyIdentifierCore(XmlReader)

Gets a value that indicates whether the key identifier core can be read using the specified reader.(Overrides SecurityTokenSerializer.CanReadKeyIdentifierCore(XmlReader).)

System_CAPS_pubmethodCanReadToken(XmlReader)

Determines whether this serializer can read the security token pointed at by the specified XML reader.(Inherited from SecurityTokenSerializer.)

System_CAPS_protmethodCanReadTokenCore(XmlReader)

Gets a value that indicates whether the token core can be read using the specified reader.(Overrides SecurityTokenSerializer.CanReadTokenCore(XmlReader).)

System_CAPS_pubmethodCanWriteKeyIdentifier(SecurityKeyIdentifier)

Determines whether this serializer can write the specified key identifier. (Inherited from SecurityTokenSerializer.)

System_CAPS_pubmethodCanWriteKeyIdentifierClause(SecurityKeyIdentifierClause)

Determines whether this serializer can write the specified key identifier clause.(Inherited from SecurityTokenSerializer.)

System_CAPS_protmethodCanWriteKeyIdentifierClauseCore(SecurityKeyIdentifierClause)

Gets a value that indicates whether the key identifier clause core with a specified key identifier clause can be written.(Overrides SecurityTokenSerializer.CanWriteKeyIdentifierClauseCore(SecurityKeyIdentifierClause).)

System_CAPS_protmethodCanWriteKeyIdentifierCore(SecurityKeyIdentifier)

Gets a value that indicates whether the key identifier core with a specified key identifier clause can be written.(Overrides SecurityTokenSerializer.CanWriteKeyIdentifierCore(SecurityKeyIdentifier).)

System_CAPS_pubmethodCanWriteToken(SecurityToken)

Determines whether this serializer can write the specified security token to XML.(Inherited from SecurityTokenSerializer.)

System_CAPS_protmethodCanWriteTokenCore(SecurityToken)

Gets a value that indicates whether the token core with a specified security token can be written.(Overrides SecurityTokenSerializer.CanWriteTokenCore(SecurityToken).)

System_CAPS_pubmethodCreateKeyIdentifierClauseFromTokenXml(XmlElement, SecurityTokenReferenceStyle)

Creates a key identifier clause from a token expressed as XML.

System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_protmethodGetTokenTypeUri(Type)

Gets the URI of the security token of the specified type.

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_pubmethodReadKeyIdentifier(XmlReader)

Reads the key identifier using specified XML reader.(Inherited from SecurityTokenSerializer.)

System_CAPS_pubmethodReadKeyIdentifierClause(XmlReader)

Reads the key identifier clause using specified XML reader.(Inherited from SecurityTokenSerializer.)

System_CAPS_protmethodReadKeyIdentifierClauseCore(XmlReader)

Reads the key identifier clause core using the specified XmlReader.(Overrides SecurityTokenSerializer.ReadKeyIdentifierClauseCore(XmlReader).)

System_CAPS_protmethodReadKeyIdentifierCore(XmlReader)

Reads the key identifier core using the specified XmlReader.(Overrides SecurityTokenSerializer.ReadKeyIdentifierCore(XmlReader).)

System_CAPS_pubmethodReadToken(XmlReader, SecurityTokenResolver)

Reads the security token pointed at by the specified XML reader.(Inherited from SecurityTokenSerializer.)

System_CAPS_protmethodReadTokenCore(XmlReader, SecurityTokenResolver)

Reads the token core using the specified XmlReader.(Overrides SecurityTokenSerializer.ReadTokenCore(XmlReader, SecurityTokenResolver).)

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

System_CAPS_pubmethodTryCreateKeyIdentifierClauseFromTokenXml(XmlElement, SecurityTokenReferenceStyle, SecurityKeyIdentifierClause)

Attempts to create a key identifier clause from a token expressed as XML.

System_CAPS_pubmethodWriteKeyIdentifier(XmlWriter, SecurityKeyIdentifier)

Writes the specified key identifier using the specified XML writer.(Inherited from SecurityTokenSerializer.)

System_CAPS_pubmethodWriteKeyIdentifierClause(XmlWriter, SecurityKeyIdentifierClause)

Writes the specified key identifier clause using the specified XML writer.(Inherited from SecurityTokenSerializer.)

System_CAPS_protmethodWriteKeyIdentifierClauseCore(XmlWriter, SecurityKeyIdentifierClause)

Writes the key identifier clause core with a specified key identifier clause using the specified XmlWriter.(Overrides SecurityTokenSerializer.WriteKeyIdentifierClauseCore(XmlWriter, SecurityKeyIdentifierClause).)

System_CAPS_protmethodWriteKeyIdentifierCore(XmlWriter, SecurityKeyIdentifier)

Writes the key identifier core with a specified key identifier clause using the specified XmlWriter.(Overrides SecurityTokenSerializer.WriteKeyIdentifierCore(XmlWriter, SecurityKeyIdentifier).)

System_CAPS_pubmethodWriteToken(XmlWriter, SecurityToken)

Writes the specified security token using the specified XML writer. (Inherited from SecurityTokenSerializer.)

System_CAPS_protmethodWriteTokenCore(XmlWriter, SecurityToken)

Writes the token core with a specified security token using the specified XmlWriter.(Overrides SecurityTokenSerializer.WriteTokenCore(XmlWriter, SecurityToken).)

The following code demonstrates a custom override of this class.

public class CreditCardSecurityTokenSerializer : WSSecurityTokenSerializer
{
    public CreditCardSecurityTokenSerializer(SecurityTokenVersion version) : base() { }

    protected override bool CanReadTokenCore(XmlReader reader)
    {
        XmlDictionaryReader localReader = XmlDictionaryReader.CreateDictionaryReader(reader);
        if (reader == null)
        {
            throw new ArgumentNullException("reader");
        }
        if (reader.IsStartElement(Constants.CreditCardTokenName, Constants.CreditCardTokenNamespace))
        {
            return true;
        }
        return base.CanReadTokenCore(reader);
    }

    protected override SecurityToken ReadTokenCore(XmlReader reader, SecurityTokenResolver tokenResolver)
    {
        if (reader == null)
        {
            throw new ArgumentNullException("reader");
        }
        if (reader.IsStartElement(Constants.CreditCardTokenName, Constants.CreditCardTokenNamespace))
        {
            string id = reader.GetAttribute(Constants.Id, Constants.WsUtilityNamespace);

            reader.ReadStartElement();

            // Read the credit card number.
            string creditCardNumber = reader.ReadElementString(Constants.CreditCardNumberElementName, Constants.CreditCardTokenNamespace);

            // Read the expiration date.
            string expirationTimeString = reader.ReadElementString(Constants.CreditCardExpirationElementName, Constants.CreditCardTokenNamespace);
            DateTime expirationTime = XmlConvert.ToDateTime(expirationTimeString, XmlDateTimeSerializationMode.Utc);

            // Read the issuer of the credit card.
            string creditCardIssuer = reader.ReadElementString(Constants.CreditCardIssuerElementName, Constants.CreditCardTokenNamespace);
            reader.ReadEndElement();

            CreditCardInfo cardInfo = new CreditCardInfo(creditCardNumber, creditCardIssuer, expirationTime);

            return new CreditCardToken(cardInfo, id);
        }
        else
        {
            return WSSecurityTokenSerializer.DefaultInstance.ReadToken(reader, tokenResolver);
        }
    }

    protected override bool CanWriteTokenCore(SecurityToken token)
    {
        if (token is CreditCardToken)
        {
            return true;
        }
        else
        {
            return base.CanWriteTokenCore(token);
        }
    }

    protected override void WriteTokenCore(XmlWriter writer, SecurityToken token)
    {
        if (writer == null) 
        { 
            throw new ArgumentNullException("writer"); 
        }
        if (token == null) 
        { 
            throw new ArgumentNullException("token"); 
        }

        CreditCardToken c = token as CreditCardToken;
        if (c != null)
        {
            writer.WriteStartElement(Constants.CreditCardTokenPrefix, Constants.CreditCardTokenName, Constants.CreditCardTokenNamespace);
            writer.WriteAttributeString(Constants.WsUtilityPrefix, Constants.Id, Constants.WsUtilityNamespace, token.Id);
            writer.WriteElementString(Constants.CreditCardNumberElementName, Constants.CreditCardTokenNamespace, c.CardInfo.CardNumber);
            writer.WriteElementString(Constants.CreditCardExpirationElementName, Constants.CreditCardTokenNamespace, XmlConvert.ToString(c.CardInfo.ExpirationDate, XmlDateTimeSerializationMode.Utc));
            writer.WriteElementString(Constants.CreditCardIssuerElementName, Constants.CreditCardTokenNamespace, c.CardInfo.CardIssuer);
            writer.WriteEndElement();
            writer.Flush();
        }
        else
        {
            base.WriteTokenCore(writer, token);
        }
    }
}

.NET Framework
Available since 3.0

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show: