SoapInputFilter Class
Provides a base class for defining an input filter for SOAP messages.
Namespace: Microsoft.Web.Services2
Assembly: Microsoft.Web.Services2 (in microsoft.web.services2.dll)
Usage
'Usage
Dim soapInputFilter1 As New SoapInputFilter()
Syntax
'Declaration
MustInherit Public Class SoapInputFilter
public abstract class SoapInputFilter
public abstract ref class SoapInputFilter
public abstract class SoapInputFilter
public abstract class SoapInputFilter
Example
The following code example creates a custom input filter that adds a culture info ID to a SOAP envelope.
' <summary>
' The following example creates a custom input filter
' by inheriting from SoapInputFilter. It overrides
' ProcessMessage which looks for a CultureInfoId
' </summary>
Namespace CustomFilterLibrary
Public Class CultureInfoInputFilter
Inherits SoapInputFilter
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 Microsoft.Web.Services2.SoapEnvelope)
'Retrieve the header element associated with the SOAP envelope.
Dim soapHeader As XmlElement = envelope.Header
'Search for the custom header.
Dim matches As XmlNodeList = soapHeader.GetElementsByTagName(CustomHeaderName, CustomHeaderUri)
If matches.Count > 1 Then
Throw New SoapHeaderException("Multiple <CustomHeader> elements were found in the SOAP Header", SoapHeaderException.ClientFaultCode)
End If
If matches.Count = 1 Then
Dim customHeader As XmlElement = matches(0) '
Dim cultureInfoAttribute As XmlAttribute = customHeader.Attributes(CustomHeaderAttributeName, CustomHeaderUri)
If cultureInfoAttribute Is Nothing Then
Throw New SoapHeaderException("The id attribute was not found in CultureInfo", SoapHeaderException.ClientFaultCode)
Else
'Stuff the Culture Info into the envelope if it is found
envelope.Context("CultureInfoId") = cultureInfoAttribute.Value
'Another possibility here would be to terminate the
'request if your application does not support this culture
'The following code would force back the response and terminate the request:
'System.Web.HttpContext.Current.Response.OutputStream.Flush();
'System.Web.HttpContext.Current.ApplicationInstance.CompleteRequest();
End If
End If
End Sub 'ProcessMessage
End Class 'CultureInfoInputFilter
End Namespace
namespace CustomFilterLibrary
{
/// <summary>
/// The following example creates a custom input filter
/// by inheriting from SoapInputFilter. It overrides
/// ProcessMessage which looks for a CultureInfoId
/// </summary>
public class CultureInfoInputFilter : SoapInputFilter
{
const string CustomHeaderName = "CultureInfo";
const string CustomHeaderUri = "http://www.woodgrovebank.com";
const string CustomHeaderAttributeName = "Id";
public override void ProcessMessage(Microsoft.Web.Services.SoapEnvelope envelope)
{
//Retrieve the header element associated with the SOAP envelope.
XmlElement soapHeader = envelope.Header;
//Search for the custom header.
XmlNodeList matches = soapHeader.GetElementsByTagName(CustomHeaderName, CustomHeaderUri);
if (matches.Count > 1)
{
throw new SoapHeaderException("Multiple <CustomHeader> elements were found in the SOAP Header", SoapHeaderException.ClientFaultCode);
}
if (matches.Count == 1)
{
XmlElement customHeader = matches[0] as XmlElement;
XmlAttribute cultureInfoAttribute = customHeader.Attributes[CustomHeaderAttributeName, CustomHeaderUri];
if (cultureInfoAttribute == null)
{
throw new SoapHeaderException("The id attribute was not found in CultureInfo", SoapHeaderException.ClientFaultCode);
}
else
{
//Stuff the Culture Info into the envelope if it is found.
envelope.Context["CultureInfoId"] = cultureInfoAttribute.Value;
//Another possibility here would be to terminate the
//request if your application does not support this culture.
//The following code would force back the response and terminate the request:
//System.Web.HttpContext.Current.Response.OutputStream.Flush();
//System.Web.HttpContext.Current.ApplicationInstance.CompleteRequest();
}
}
}
}
}
The following code example demonstrates a Web service method that retrieves a culture info ID from a SOAP envelope.
<WebMethod()> _
Public Function HelloLocale() As String
Dim requestContext As SoapContext = HttpSoapContext.RequestContext
'Retrieving the CultureInfoId which was stuffed into the envelope when
'the custom input filter processed the message.
Return requestContext.Envelope.Context("CultureInfoId").ToString()
End Function 'HelloLocale
[WebMethod]
public string HelloLocale()
{
SoapContext requestContext = HttpSoapContext.RequestContext;
//Retrieving the CultureInfoId which was stuffed into the envelope when
//the custom input filter processed the message.
return requestContext.Envelope.Context["CultureInfoId"].ToString();
}
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 SoapInputFilter, you must override the ProcessMessage method.
Inheritance Hierarchy
System.Object
Microsoft.Web.Services2.SoapInputFilter
Microsoft.Web.Services2.Diagnostics.TraceInputFilter
Microsoft.Web.Services2.Policy.PolicyVerificationInputFilter
Microsoft.Web.Services2.Referral.ReferralInputFilter
Microsoft.Web.Services2.Security.SecurityInputFilter
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