//----------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------- namespace System.IdentityModel.Protocols.WSTrust { using System.Xml; /// /// Class for serializing a WS-Trust Feb 2005 RequestSecurityTokenResponse to an XmlWriter /// public class WSTrustFeb2005ResponseSerializer : WSTrustResponseSerializer { /// /// Deserializes the RSTR from the XmlReader to a RequestSecurityTokenResponse object. /// /// XML reader over the RSTR /// Current Serialization context. /// RequestSecurityTokenResponse object if the deserialization was successful /// The given reader or context parameter is null /// There was an error parsing the RSTR public override RequestSecurityTokenResponse ReadXml(XmlReader reader, WSTrustSerializationContext context) { if (reader == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reader"); } if (context == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context"); } return WSTrustSerializationHelper.CreateResponse(reader, context, this, WSTrustConstantsAdapter.TrustFeb2005); } /// /// Override of the base class that Reads a specific child element inside the RSTR. /// /// Reader pointing at an element to read inside the RSTR. /// The RequestSecurityTokenResponse element that is being populated from the reader. /// Current Serialization context. /// Either reader or rstr or context parameter is null. /// Unable to deserialize the current parameter. public override void ReadXmlElement(XmlReader reader, RequestSecurityTokenResponse rstr, WSTrustSerializationContext context) { if (reader == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reader"); } if (rstr == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("rstr"); } if (context == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context"); } WSTrustSerializationHelper.ReadRSTRXml(reader, rstr, context, WSTrustConstantsAdapter.TrustFeb2005); } /// /// Writes out the supported elements on the response object. /// /// The response instance /// The writer to write to /// Current Serialization context. /// Either rstr or writer or context parameter is null. public override void WriteKnownResponseElement(RequestSecurityTokenResponse rstr, XmlWriter writer, WSTrustSerializationContext context) { if (rstr == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("rstr"); } if (writer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writer"); } if (context == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context"); } WSTrustSerializationHelper.WriteKnownResponseElement(rstr, writer, context, this, WSTrustConstantsAdapter.TrustFeb2005); } /// /// Serializes the given RequestSecurityTokenResponse into the XmlWriter /// /// RequestSecurityTokenRespone object to be serialized /// XML writer to serialize into /// Current Serialization context. /// The response or writer or context parameter is null. public override void WriteXml(RequestSecurityTokenResponse response, XmlWriter writer, WSTrustSerializationContext context) { if (response == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("response"); } if (writer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writer"); } if (context == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context"); } WSTrustSerializationHelper.WriteResponse(response, writer, context, this, WSTrustConstantsAdapter.TrustFeb2005); } /// /// Override of the Base class method that writes a specific RSTR parameter to the outgoing stream. /// /// Writer to which the RSTR is serialized /// The Local name of the element to be written. /// The value of the element. /// The entire RSTR object that is being serialized. /// Current Serialization context. /// Either writer or rstr or context is null. /// elementName is null or an empty string. public override void WriteXmlElement(XmlWriter writer, string elementName, object elementValue, RequestSecurityTokenResponse rstr, WSTrustSerializationContext context) { if (writer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writer"); } if (string.IsNullOrEmpty(elementName)) { throw DiagnosticUtility.ThrowHelperArgumentNullOrEmptyString("elementName"); } if (rstr == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("rstr"); } if (context == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context"); } WSTrustSerializationHelper.WriteRSTRXml(writer, elementName, elementValue, context, WSTrustConstantsAdapter.TrustFeb2005); } /// /// Checks if the given reader is positioned at a RequestSecurityTokenResponse element with namespace /// 'http://schemas.xmlsoap.org/ws/2005/02/trust' /// /// The reader to read from /// /// 'True' if the reader is positioned at a RequestSecurityTokenResponse element with namespace /// 'http://schemas.xmlsoap.org/ws/2005/02/trust'. /// /// The input argument is null. public override bool CanRead(XmlReader reader) { if (reader == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reader"); } return reader.IsStartElement(WSTrustFeb2005Constants.ElementNames.RequestSecurityTokenResponse, WSTrustFeb2005Constants.NamespaceURI); } } }