Security Class
Represents a security header that will be added to the SOAP request.
Namespace: Microsoft.Web.Services2.Security
Assembly: Microsoft.Web.Services2 (in microsoft.web.services2.dll)
Usage
'Usage
Dim security1 As New Security()
Syntax
'Declaration
Public Class Security
Inherits SoapHeader
public class Security : SoapHeader
public ref class Security : public SoapHeader
public class Security extends SoapHeader
public class Security extends SoapHeader
Example
The following code example demonstrates how a receiver can retrieve the an X.509 certificate that was used to sign a SOAP request and then use that to encrypt the SOAP response. To encrypt the SOAP message, an instance is added to the Elements property of an instance of Security. The Microsoft.Web.Services2.SoapContext.Security property is an instance of Security.
[Visual Basic]
<WebMethod()> _
Public Function EncryptResponse(ByVal str As String) As String
Dim context As SoapContext = RequestSoapContext.Current
Dim tok As X509SecurityToken = Nothing
Dim token As X509SecurityToken
For Each token In context.Security.Tokens
If Not token Is Nothing Then
tok = token
End If
Next
' Create a new instance of the EncryptedData class passing in the security token.
Dim enc As EncryptedData = New EncryptedData(tok)
' Add the instance of EncryptedData to the SOAP response.
ResponseSoapContext.Current.Security.Elements.Add(enc)
Return str
End Function
[C#]
[WebMethod]
public string EncryptResponse( String str )
{
SoapContext context = RequestSoapContext.Current;
X509SecurityToken tok = null;
foreach( X509SecurityToken token in context.Security.Tokens)
{
if( token != null )
{
tok = token;
}
}
// Create a new instance of the EncryptedData class passing in the security token.
EncryptedData enc = new EncryptedData( tok );
// Add the instance of EncryptedData to the SOAP response.
ResponseSoapContext.Current.Security.Elements.Add( enc );
return str;
}
Remarks
A security header provides a mechanism for attaching security-related information targeted at a specific receiver. A SOAP message can have multiple security headers.
A typical security header can contain multiple tokens, signatures and encryption keys.
Note
The value of the MustUnderstand property is ignored and always has a value of true.
Remarks
Inheritance Hierarchy
System.Object
System.Web.Services.Protocols.SoapHeader
Microsoft.Web.Services2.Security.Security
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.Security Namespace