Share via


SoapOutputFilter Class

Provides a base class for defining an output filter for SOAP messages.

Namespace: Microsoft.Web.Services2
Assembly: Microsoft.Web.Services2 (in microsoft.web.services2.dll)

Usage

'Usage
Dim soapOutputFilter1 As New SoapOutputFilter()

Syntax

'Declaration
MustInherit Public Class SoapOutputFilter
public abstract class SoapOutputFilter
public abstract ref class SoapOutputFilter
public abstract class SoapOutputFilter
public abstract class SoapOutputFilter

Example

The following code example creates a custom output filter which stores the client's current culture info name in the custom header.

' <summary>
' The following example creates a custom output filter
' by inheriting from SoapOutputFilter.  It overrides
' ProcessMessage which sets the CultureInfo ID to 
' the client's current culture.
' </summary>
Namespace CustomFilterLibrary

   Public Class CultureInfoOutputFilter
      Inherits SoapOutputFilter
      Private Const CustomHeaderName As String = "CultureInfo"
      Private Const CustomHeaderUri As String = "http://www.woodgrovebank.com"
      Private Const CustomHeaderAttributeName As String = "Id"


      Public Overrides Sub ProcessMessage(ByVal envelope As SoapEnvelope)
         '
         ' Create a new SOAP Header or retrieve a reference to an existing one.
         '
         Dim soapHeader As XmlElement = envelope.CreateHeader()
         '
         ' Create a new CustomHeader with the CultureId and add it to the message.
         '
         soapHeader.AppendChild(CreateCustomHeader(soapHeader, System.Globalization.CultureInfo.CurrentCulture.Name))
      End Sub 'ProcessMessage


      Function CreateCustomHeader(ByVal header As XmlElement, ByVal AttributeValue As String) As XmlElement
         Dim document As XmlDocument = header.OwnerDocument
         Dim customHeader As XmlElement = document.CreateElement("cu", CustomHeaderName, CustomHeaderUri)
         customHeader.SetAttribute(CustomHeaderAttributeName, CustomHeaderUri, AttributeValue)
         Return customHeader
      End Function 'CreateCustomHeader
   End Class 'CultureInfoOutputFilter

End Namespace
namespace CustomFilterLibrary
{
   /// <summary>
   /// The following example creates a custom output filter
   /// by inheriting from SoapOutputFilter.  It overrides
   /// ProcessMessage which sets the CultureInfo ID to
   /// the client's current culture.
   /// </summary>
   public class CultureInfoOutputFilter : SoapOutputFilter
   {
      const string CustomHeaderName = "CultureInfo";
      const string CustomHeaderUri = "http://www.woodgrovebank.com";
      const string CustomHeaderAttributeName = "Id";

      public override void ProcessMessage(SoapEnvelope envelope)
      {
         //
         // Create a new SOAP Header or retrieve a reference to an existing one.
         //
         XmlElement soapHeader = envelope.CreateHeader();
         //
         // Create a new CustomHeader with the CultureId and add it to the message.
         //
         soapHeader.AppendChild(CreateCustomHeader(soapHeader, System.Globalization.CultureInfo.CurrentCulture.Name));
      }

      XmlElement CreateCustomHeader(XmlElement header, string AttributeValue)
      {
         XmlDocument document = header.OwnerDocument;
         XmlElement customHeader = document.CreateElement("cu", CustomHeaderName, CustomHeaderUri);
         customHeader.SetAttribute(CustomHeaderAttributeName, CustomHeaderUri, AttributeValue);
         return customHeader;
      }
   }
}

The following code example demonstrated a client using a CultureInfoOutputFilter.

<STAThread()> _
Public Overloads Shared Sub Main()

   ' Create The Soap Message
   Dim envelope As New SoapEnvelope
   Dim body As XmlElement = envelope.CreateBody()
   envelope.Envelope.AppendChild(body)
   'Create an instance of the CultureInfo output filter
   Dim ciOutput As New CultureInfoOutputFilter
   'Process the messsage
   ciOutput.ProcessMessage(envelope)
   'Instantiate the WSE proxy (created by adding a web reference).
   Dim Proxy As New WseSamplesServiceWse
   'Add a CultureInfoOutput filter to the OutputFilters collection of the pipeline.
   Proxy.Pipeline.OutputFilters.Add(New CultureInfoOutputFilter)
   'Execute the web method.
   Dim ret As String
   ret = Proxy.HelloLocale()
   Console.Write(ret)

End Sub 'Main
[STAThread]
static void Main(string[] args)
{
   // Create The Soap Message
   SoapEnvelope envelope = new SoapEnvelope();
   XmlElement body = envelope.CreateBody();
   envelope.Envelope.AppendChild(body);
   //Create an instance of the CultureInfo output filter
   CultureInfoOutputFilter ciOutput = new CultureInfoOutputFilter();
   //Process the messsage
   ciOutput.ProcessMessage(envelope);
   //Instantiate the WSE proxy (created by adding a web reference).
   WseSamplesServiceWse Proxy = new WseSamplesServiceWse();
   //Add a CultureInfoOutput filter to the OutputFilters collection of the pipeline.
   Proxy.Pipeline.OutputFilters.Add(new CultureInfoOutputFilter());
   //Execute the web method.
   string ret = Proxy.HelloLocale();
   Console.Write(ret);
}

Remarks

To access the current SOAP context from within a custom filter, use the Microsoft.Web.Services2.SoapContext.Current property. The Microsoft.Web.Services2.RequestSoapContext.Current and Microsoft.Web.Services2.ResponseSoapContext.Current properties are not valid during pipeline processing when customs filters execute.

Notes to Inheritors: When you inherit from SoapOutputFilter, you must override the ProcessMessage method.

Inheritance Hierarchy

System.Object
  Microsoft.Web.Services2.SoapOutputFilter
     Microsoft.Web.Services2.Diagnostics.TraceOutputFilter
     Microsoft.Web.Services2.Policy.PolicyEnforcementOutputFilter
     Microsoft.Web.Services2.Referral.ReferralOutputFilter
     Microsoft.Web.Services2.Security.SecurityOutputFilter

Thread Safety

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

Platforms

Development Platforms

Windows XP Home Edition, Windows XP Professional, Windows Server 2003, Windows Longhorn, and Windows 2000

Target Platforms

Windows 2000, Windows 2000 Server, Windows 2000 Advanced Server, Windows XP Home Edition, Windows XP Professional, Windows Server 2003, Windows Longhorn, Pocket PC, Windows CE, Smart Phone

See Also

Reference

Microsoft.Web.Services2 Namespace

Other Resources

SoapOutputFilter Members