Condividi tramite


How to: Migrate Custom Filters to Custom Policy Assertions

Custom filters that were written for previous versions of the Web Services Enhancements for Microsoft .NET (WSE) must be migrated to custom policy assertions for WSE 3.0. Policy assertions are different from WSE 2.0 custom filters in that custom filters filter only a portion of the SOAP messages exchanged between a client and a Web service; policy assertions can filter all the messages exchanged between a client and a Web service. That is, policy assertions in WSE 3.0 contain up to four custom filters for SOAP messages sent between a client and a Web service. These four filters are input and output filters for both the client and the Web service.

To migrate a custom filter to a custom policy assertion

  1. Change the class that the custom filter derives from to SoapFilter, ReceiveSecurityFilter, or SendSecurityFilter.

    For custom filters that do not secure the SOAP message, such as a trace filter, derive the class from SoapFilter. For custom filters that secure the SOAP message, derive the class from ReceiveSecurityFilter or SendSecurityFilter when the custom filter is an input or output filter, respectively.

    The following code examples show how to change the class that the custom filter derives from to SoapFilter for a custom filter that does not secure a SOAP message.

    WSE 2.0

    Public Class CultureInfoInputFilter Inherits SoapInputFilter
    
    public class CultureInfoInputFilter : SoapInputFilter
    

    WSE 3.0

    Public Class CultureInfoInputFilter
        Inherits SoapFilter
    
    public class CultureInfoInputFilter : SoapFilter
    
  2. Change the function definition for the method that filters the SOAP message.

    For custom filters that do not secure the SOAP message, change the return type on the ProcessMessage method to SoapFilterResult. To match the WSE 2.0 functionality, return Continue.

    For custom output filters that secure the SOAP message, add a SecureMessage method and move the code from the ProcessMessage method to the SecureMessage method.

    For custom input filters that secure the SOAP message, add a ValidateMessageSecurity method and move the code from the ProcessMessage method to the ValidateMessageSecurity method.

    The following code examples show how to change the return type on the ProcessMessage method to SoapFilterResult.

    WSE 2.0

    Public Overrides Sub ProcessMessage(ByVal envelope As SoapEnvelope)
    
    public override void ProcessMessage(SoapEnvelope envelope)
    

    WSE 3.0

    Public Overrides Function ProcessMessage(ByVal envelope As SoapEnvelope) As SoapFilterResult
    
    public override SoapFilterResult ProcessMessage(SoapEnvelope envelope)
    
  3. Create a custom policy assertion.

    1. Create a class that derives from PolicyAssertion or SecurityPolicyAssertion.
      Derive the class from SecurityPolicyAssertion when the custom filter secures a SOAP message; otherwise, derive the class from PolicyAssertion.

      Note

      Although you are not required to create a class that derives from SecurityPolicyAssertion when the custom filter secures a SOAP message, doing so makes it easier to support a secure conversation, digital signature confirmation, and the use of DerivedKeyToken security tokens. These features are available to classes that derive from PolicyAssertion, but they are easier to use with the SecurityPolicyAssertion class.

      The following code example creates a policy assertion that does not secure a SOAP message.

      Class CustomCultureInfoAssertion
          Inherits PolicyAssertion
      
      class CustomCultureInfoAssertion : PolicyAssertion
      
    2. Return a new instance of the custom filter in one of the following methods: CreateClientInputFilter, CreateClientOutputFilter, CreateServiceInputFilter, or CreateServiceOutputFilter.
      These methods determine when the custom filter is called by WSE. The CreateClientInputFilter and CreateClientOutputFilter methods control the input and output filters installed on SOAP messages that are received and sent by a client. Likewise, the CreateServiceInputFilter and CreateServiceOutputFilter methods control the input and output filters installed on SOAP messages that are received and sent by a Web service.
      The following code example installs the CultureInfoInputFilter as an input filter for the Web service.

      Public Overrides Function CreateServiceInputFilter(ByVal context As FilterCreationContext) As SoapFilter
          Return New CultureInfoInputFilter
      End Function 'CreateServiceInputFilter
      
      public override SoapFilter CreateServiceInputFilter(FilterCreationContext context)
      {
          return new CultureInfoInputFilter();
      }
      

      For more information about creating a custom policy assertion, see How to: Create a Custom Policy Assertion that Secures SOAP Messages.

See Also

Tasks

How to: Create a Custom Policy Assertion that Secures SOAP Messages
How to: Secure an Application Using a Custom Policy Assertion