Solved

Logging in using UsernameToken using WSE 3.0

Posted on 2006-11-26
2
475 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Problem to Popup 37 80
Whats wrong with this query 21 39
asp.net mvc5 3 37
ASP.net VB.net Email  a webpage 3 26
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

758 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

22 Experts available now in Live!

Get 1:1 Help Now