WSTrustResponseBodyWriter.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------
  4. namespace System.ServiceModel.Security
  5. {
  6. using System;
  7. using System.IdentityModel.Protocols.WSTrust;
  8. using System.ServiceModel.Channels;
  9. using System.Xml;
  10. using RSTR = System.IdentityModel.Protocols.WSTrust.RequestSecurityTokenResponse;
  11. /// <summary>
  12. /// Defines a Body Writer that writes out the RSTR to a outgoing message.
  13. /// </summary>
  14. public class WSTrustResponseBodyWriter : BodyWriter
  15. {
  16. WSTrustResponseSerializer _serializer;
  17. RSTR _rstr;
  18. WSTrustSerializationContext _context;
  19. /// <summary>
  20. /// Initializes an instance of <see cref="WSTrustResponseBodyWriter"/>
  21. /// </summary>
  22. /// <param name="requestSecurityTokenResponse">The Response object that can write the body contents.</param>
  23. /// <param name="serializer">Serializer to use for serializing the RSTR.</param>
  24. /// <param name="context">The <see cref="WSTrustSerializationContext"/> of this request.</param>
  25. /// <exception cref="ArgumentNullException">serializer parameter is null.</exception>
  26. public WSTrustResponseBodyWriter(RSTR requestSecurityTokenResponse, WSTrustResponseSerializer serializer, WSTrustSerializationContext context)
  27. : base( true )
  28. {
  29. if ( serializer == null )
  30. {
  31. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull( "serializer" );
  32. }
  33. if ( requestSecurityTokenResponse == null )
  34. {
  35. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("requestSecurityTokenResponse");
  36. }
  37. if ( context == null )
  38. {
  39. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull( "context" );
  40. }
  41. _serializer = serializer;
  42. _rstr = requestSecurityTokenResponse;
  43. _context = context;
  44. }
  45. /// <summary>
  46. /// Override of the base class method. Serializes the RSTR to the outgoing stream.
  47. /// </summary>
  48. /// <param name="writer">Writer to which the RSTR should be written.</param>
  49. protected override void OnWriteBodyContents( XmlDictionaryWriter writer )
  50. {
  51. _serializer.WriteXml( _rstr, writer, _context );
  52. }
  53. }
  54. }