Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Logging in using UsernameToken using WSE 3.0

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

790 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