//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace System.ServiceModel.Security
{
using System;
using System.ServiceModel.Diagnostics;
using System.ServiceModel.Channels;
using System.Xml;
using System.Diagnostics;
using System.IdentityModel.Protocols.WSTrust;
///
/// Defines a Body Writer that writes out a RequestSecurityToken into an XmlDictionaryWriter.
///
public class WSTrustRequestBodyWriter : BodyWriter
{
WSTrustSerializationContext _serializationContext;
System.IdentityModel.Protocols.WSTrust.RequestSecurityToken _requestSecurityToken;
WSTrustRequestSerializer _serializer;
///
/// Constructor for the WSTrustRequestBodyWriter.
///
/// The RequestSecurityToken object to be serialized in the outgoing Message.
/// Serializer is responsible for writting the requestSecurityToken into a XmlDictionaryWritter.
/// Context for the serialization.
/// The 'requestSecurityToken' is null.
/// The 'serializer' is null.
/// The 'serializationContext' is null.
public WSTrustRequestBodyWriter(System.IdentityModel.Protocols.WSTrust.RequestSecurityToken requestSecurityToken, WSTrustRequestSerializer serializer, WSTrustSerializationContext serializationContext)
: base(true)
{
if (requestSecurityToken == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("requestSecurityToken");
}
if (serializer == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("serializer");
}
if (serializationContext == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("serializationContext");
}
_requestSecurityToken = requestSecurityToken;
_serializer = serializer;
_serializationContext = serializationContext;
}
///
/// Override of the base class method. Serializes the requestSecurityToken to the outgoing stream.
///
/// Writer into which the requestSecurityToken should be written.
protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
{
_serializer.WriteXml(_requestSecurityToken, writer, _serializationContext);
}
}
}