Share via


Signature Constructor (SecurityToken)

Initializes a new instance of the Signature class with the specified security token.

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

Usage

'Usage
Dim token As SecurityToken
Dim signature1 As New Signature(token)

Syntax

'Declaration
Public Sub New( _
    ByVal token As SecurityToken _
)
public Signature(
    SecurityToken token
);
public: Signature(
    SecurityToken^ token
);
public Signature(
    SecurityToken token
);
public function Signature(
     token : SecurityToken
);

Parameters

Example

The following code example signs a SOAP message using an X.509 certificate. The GetSecurityTokenmethod retrieves an X.509 certificate from the certificate store. To see the code for it, see How to: Sign a SOAP Message Using an X.509 Certificate.

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

        ' Gets the X.509 certificate for signing the SOAP message.
        Dim signatureToken As X509SecurityToken = GetSecurityToken(True)

        If signatureToken Is Nothing Then
            Return
        End If

        ' Adds the X.509 certificate to the WS-Security header.
        requestContext.Security.Tokens.Add(signatureToken)

        ' Signs the SOAP message using the X.509 certifcate.
        requestContext.Security.Elements.Add(New MessageSignature(signatureToken))

        ' Sets the TTL to one minute.
        requestContext.Security.Timestamp.TtlInSeconds = 60

        ' Makes the SOAP request to the XML Web service.
        textBoxResult.Text = svc.AddNumbers(a, b).ToString()
    Catch ex As Exception

        MessageBox.Show(ex.ToString())
    End Try
End Sub 'Sign 
    // Gets the SoapContext for the SOAP request that is to be sent
    // to the XML Web service.
    Service1Wse svc = new Service1Wse();
    SoapContext requestContext = svc.RequestSoapContext;

    // Gets the X.509 certificate for signing the SOAP message.
    X509SecurityToken signatureToken = GetSecurityToken(true);
    if (signatureToken == null) 
    {
        return;
    }

    // Adds the X.509 certificate to the WS-Security header.
    requestContext.Security.Tokens.Add(signatureToken);

    // Signs the SOAP message using the X.509 certifcate.
    requestContext.Security.Elements.Add(new MessageSignature(signatureToken));

    // Sets the TTL to one minute.
    requestContext.Security.Timestamp.TtlInSeconds = 60;

    // Makes the SOAP request to the XML Web service.
    textBoxResult.Text = svc.AddNumbers(a,b).ToString() ;
}
catch (Exception ex) 
{
    MessageBox.Show(ex.ToString());
}

Exceptions

Exception type Condition
System.ArgumentNullException

tokenis null.

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

Signature Class
Microsoft.Web.Services2.Security Namespace

Other Resources

Signature Members