Solved

Logging in using UsernameToken using WSE 3.0

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

809 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