Solved

Logging in using UsernameToken using WSE 3.0

Posted on 2006-11-26
2
484 Views
Last Modified: 2012-05-05
Hello,

I have added a reference to the asmx file given by the our 3rd party vendor. On buttonclick I am trying to login to the tool with the code below

Whenever I try to run the app and provide the username,pwd and hit on the login buttn I am getting this error

System.NullReferenceException: Object reference not set to an instance of an object.

at this Line "UsernameToken userTok = new UsernameToken(userName, pwd, Microsoft.Web.Services3.Security.Tokens.PasswordOption.SendPlainText);"

When I build the solution it says build succeeded.

Please help

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Security.Permissions;
using Microsoft.Web.Services3.Security.Tokens;
using Testing;


public partial class _Default : System.Web.UI.Page
{
    private static Testing.InterfaceWse binding;
   



    protected void Page_Load(object sender, EventArgs e)
    {

    }    
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        SecurityContextToken sct = null;
        String userName = txtUserName.Text;
        String pwd = txtPassword.Text;

        if (userName.Length == 0 || pwd.Length == 0)
        {
            Response.Write("Please specify username and password.");
            return;
        }

        // Create a new instance of the web service proxy class
        binding = new Testing.InterfaceWse();

        // Create the UsernameToken with your username and password

        UsernameToken userTok = new UsernameToken("test", "test", Microsoft.Web.Services3.Security.Tokens.PasswordOption.SendPlainText);
       
        binding.RequestSoapContext.Security.Tokens.Add(userTok);
       
        // Call the Login method
        Testing.LoginCredentials loginCreds = binding.Login();
        // Verify that the login was successful
        if (loginCreds.CurrentLoginStatus != Testing.LoginStatus.Success)
        {
            // Display to user why login failed
            Response.Write (loginCreds.CurrentLoginStatus.ToString());
            return;
        }

        // Login was successful, now grab the SecurityContextToken returned
        // Loop through each of the tokens in  response
        foreach (SecurityToken tok in binding.ResponseSoapContext.Security.Tokens)
        {
            // Get the SecurityContextToken that was returned
            if (tok is SecurityContextToken)
                sct = tok as SecurityContextToken;
        }
        // Remove any tokens from the request
        binding.RequestSoapContext.Security.Tokens.Clear();
        // Add the SecurityContextToken
        binding.RequestSoapContext.Security.Tokens.Add(sct);

        return;
       
    }
   
}
0
Comment
Question by:rowmark
2 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 18018675
Are you trying to implement impersonation with the UsernameToken?

Bob
0
 

Author Comment

by:rowmark
ID: 18038499
yes
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now