rowmark
asked on
Logging in using UsernameToken using WSE 3.0
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.NullReferenceExcept ion: Object reference not set to an instance of an object.
at this Line "UsernameToken userTok = new UsernameToken(userName, pwd, Microsoft.Web.Services3.Se curity.Tok ens.Passwo rdOption.S endPlainTe xt);"
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.Permission s;
using Microsoft.Web.Services3.Se curity.Tok ens;
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.Se curity.Tok ens.Passwo rdOption.S endPlainTe xt);
binding.RequestSoapContext .Security. Tokens.Add (userTok);
// Call the Login method
Testing.LoginCredentials loginCreds = binding.Login();
// Verify that the login was successful
if (loginCreds.CurrentLoginSt atus != Testing.LoginStatus.Succes s)
{
// Display to user why login failed
Response.Write (loginCreds.CurrentLoginSt atus.ToStr ing());
return;
}
// Login was successful, now grab the SecurityContextToken returned
// Loop through each of the tokens in response
foreach (SecurityToken tok in binding.ResponseSoapContex t.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.Cle ar();
// Add the SecurityContextToken
binding.RequestSoapContext .Security. Tokens.Add (sct);
return;
}
}
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.NullReferenceExcept
at this Line "UsernameToken userTok = new UsernameToken(userName, pwd, Microsoft.Web.Services3.Se
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.
using System.Web.UI.HtmlControls
using System.Security.Permission
using Microsoft.Web.Services3.Se
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.Se
binding.RequestSoapContext
// Call the Login method
Testing.LoginCredentials loginCreds = binding.Login();
// Verify that the login was successful
if (loginCreds.CurrentLoginSt
{
// Display to user why login failed
Response.Write (loginCreds.CurrentLoginSt
return;
}
// Login was successful, now grab the SecurityContextToken returned
// Loop through each of the tokens in response
foreach (SecurityToken tok in binding.ResponseSoapContex
{
// Get the SecurityContextToken that was returned
if (tok is SecurityContextToken)
sct = tok as SecurityContextToken;
}
// Remove any tokens from the request
binding.RequestSoapContext
// Add the SecurityContextToken
binding.RequestSoapContext
return;
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER