Share via


UsernameToken.PasswordOption Property

Gets or sets how the password associated with the security token is sent in SOAP messages.

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

Usage

'Usage
Dim usernameToken1 As UsernameToken

Dim returnValue As PasswordOption
returnValue = usernameToken1.PasswordOption

Syntax

'Declaration
Public ReadOnly Property PasswordOption() As PasswordOption
public PasswordOption PasswordOption {get;}
public: property PasswordOption^ PasswordOption{
    PasswordOption^ get();
}
public PasswordOption get_PasswordOption();
public function get PasswordOption() : PasswordOption;

Property Value

One of the PasswordOption values that specifies how the password associated with the security token is sent in SOAP messages.

Example

The following code example signs a SOAP message using a UsernameToken, specifying that the SHA-1 hash of the password be sent in the SOAP message. This sample specifies how the password is sent in the SOAP message by setting the PasswordOption property instead of using the constructor that allows you to specify that option.

' Create a UsernameToken security token.
Dim userToken As UsernameToken
userToken = New UsernameToken(username, passwordEquivalent,PasswordOption.SendHashed)
Try
    ' Create a new instance of the proxy class.
    Dim serviceProxy As New AddNumbersWse
    ' Get the SoapContext associated with the SOAP request.
    Dim requestContext As SoapContext = serviceProxy.RequestSoapContext
    ' Set the period of time in which the SOAP request expires to one minute.
    requestContext.Security.Timestamp.TtlInSeconds = 60

    ' Add the UsernameToken token to the SOAP header.
    requestContext.Security.Tokens.Add(userToken)
    ' Sign the SOAP message using the UsernameToken.
    requestContext.Security.Elements.Add(New MessageSignature(userToken))

    ' Call the Web service method.
    Dim sum As Integer = serviceProxy.AddInt(a, b)

    ' If code execution reaches here, the Web service method was
    ' successfully communicated with.
    Dim message As String = String.Format("{0} + {1} = {2}", a, b, sum)
    MessageBox.Show(message, "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch se As System.Web.Services.Protocols.SoapException
    MessageBox.Show(se.ToString())
Catch ex As Exception
    MessageBox.Show("Exception caught while invoking a web service.", ex.Message)
    Return
End Try
// Create a UsernameToken security token.
UsernameToken userToken;            
userToken = new UsernameToken(username, passwordEquivalent,PasswordOption.SendHashed);

try
{
    // Create a new instance of the proxy class.
    AddNumbersWse serviceProxy = new AddNumbersWse();
    // Get the SoapContext associated with the SOAP request.
    SoapContext requestContext = serviceProxy.RequestSoapContext;

    // Set the period of time in which the SOAP request expires to one minute.
    requestContext.Security.Timestamp.TtlInSeconds = 60;
   
    // Add the UsernameToken token to the SOAP message.
    requestContext.Security.Tokens.Add(userToken);

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

    // Call the Web service method.
    int sum = serviceProxy.AddInt(a, b);

    // If code execution reaches here, the Web service method was
    // successfully communicated with.
    string message = string.Format("{0} + {1} = {2}", a, b, sum);
    MessageBox.Show(message, "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (System.Web.Services.Protocols.SoapException se) 
{
    MessageBox.Show(se.ToString());
}
catch (Exception ex) 
{
    MessageBox.Show ("Exception caught while invoking a web service.", ex.Message );
    return;
}

Exceptions

Exception type Condition
System.ArgumentException

PasswordOption is set to a value other than Microsoft.Web.Services2.Security.Tokens.PasswordOption.SendNone when the Password property is null.

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

UsernameToken Class
Microsoft.Web.Services2.Security.Tokens Namespace

Other Resources

UsernameToken Members