SecurityContextTokenServiceClient Class

Represents a client that requests SecurityContextToken security tokens from a security token service.

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

Usage

'Usage
Dim endpoint As EndpointReference
Dim securityContextTokenServiceClient1 As New SecurityContextTokenServiceClient(endpoint)

Syntax

'Declaration
Public Class SecurityContextTokenServiceClient
    Inherits SecurityTokenServiceClient
public class SecurityContextTokenServiceClient : SecurityTokenServiceClient
public ref class SecurityContextTokenServiceClient : public SecurityTokenServiceClient
public class SecurityContextTokenServiceClient extends SecurityTokenServiceClient
public class SecurityContextTokenServiceClient extends SecurityTokenServiceClient

Example

The following code example requests a SecurityContextToken security token from a SecurityContextTokenServiceClient security token service.

' Get the SoapContext for the SOAP request that is to be sent
' to the Web service.
Dim proxy As New Service1Wse
Dim requestContext As SoapContext = proxy.RequestSoapContext

' Get the X.509 certificate for signing the SOAP message.
Dim token As X509SecurityToken = GetSecurityToken()

' Get a security token to sign the SOAP message sent to the
' security token service. 
If token Is Nothing Then
    Throw New ApplicationException("No key provided for signature.")
End If

' Create a SecurityTokenServiceClient that will get the SecurityContextToken
Dim secureConvEndpoint As String = "https://www.contoso.com/SecureConversationCS/Service1.asmx"
Dim client As SecurityContextTokenServiceClient = New SecurityContextTokenServiceClient(New EndpointReference(New Uri(secureConvEndpoint)))

' Retrieve the issuer's cert
Dim issuerToken As SecurityToken = GetServerToken()

' Request the token, use the signing token as the Base
Dim sct As SecurityContextToken = client.IssueSecurityContextTokenAuthenticated(token, issuerToken)

' Create a security token that is derived from the SecurityContextToken.
Dim derivedToken As DerivedKeyToken = New DerivedKeyToken(CType(sct, IDerivableToken))

' Add the token issued from the token issuing service to the SOAP message.
requestContext.Security.Tokens.Add(sct)

' Add the derived security token to the SOAP message.
requestContext.Security.Tokens.Add(derivedToken)

' Sign the SOAP message using the token issued from the security token service.
requestContext.Security.Elements.Add(New MessageSignature(derivedToken))

' Communicate with the Web service.
textBoxResult.Text = proxy.AddNumbers(a, b).ToString()
// Get the SoapContext for the SOAP request that is to be sent
// to the Web service.
Service1Wse proxy = new Service1Wse();
SoapContext requestContext = proxy.RequestSoapContext;

// Get the X.509 certificate for signing the SOAP message.
X509SecurityToken token = GetSecurityToken();

// Get a security token to sign the SOAP message sent to the
// security token service. 
if (token == null)
    throw new ApplicationException("No key provided for signature.");

// Create a SecurityContextTokenServiceClient that will get the SecurityContextToken
string secureConvEndpoint = "https://www.contoso.com/secureConversation.asmx";
SecurityContextTokenServiceClient client = new SecurityContextTokenServiceClient(new Uri( secureConvEndpoint ));

// retrieve server's cert
SecurityToken issuerToken = GetServerToken();

// Request the token, use the signing token as the Base
SecurityContextToken sct = client.IssueSecurityContextTokenAuthenticated(token, issuerToken);

// Create a security token that is derived from the SecurityContextToken.
DerivedKeyToken derivedToken = new DerivedKeyToken((IDerivableToken)sct);                   

// Add the token issued from the token issuing service to the SOAP message.
requestContext.Security.Tokens.Add(sct);

// Add the derived security token to the SOAP message.
requestContext.Security.Tokens.Add(derivedToken);

// Sign the SOAP message using the token.
requestContext.Security.Elements.Add(new MessageSignature(derivedToken));

// Communicate with the Web service.
textBoxResult.Text = proxy.AddNumbers(a,b).ToString() ;

Remarks

Use the SecurityContextTokenServiceClient class to request SecurityContextToken security tokens from a SecurityContextTokenService security token service. A security token service issues security tokens that are trusted by one or more target Web services. A SOAP message sender can request a security token from a security token service using the <RequestSecurityToken> element. A security token service responds to the request with a <RequestSecurityTokenResponse> element. If the security token service issues a security token as requested, the response contains the requested security token.

For more information about issuing security tokens, see Issuing Security Tokens.

Inheritance Hierarchy

System.Object
   Microsoft.Web.Services2.Messaging.SoapPort
     Microsoft.Web.Services2.Messaging.SoapSender
       Microsoft.Web.Services2.Messaging.SoapClient
         Microsoft.Web.Services2.Security.SecurityTokenServiceClient
          Microsoft.Web.Services2.Security.SecurityContextTokenServiceClient

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

Other Resources

SecurityContextTokenServiceClient Members