Im using a SOAP Header and I need to Authenticate it from the Database. So, I tried creating one Class and have one method on which, when we pass username and password it will return whether its there in the DB or not.
----- My Main Class --- [WebMethod, SoapHeader("AuthenticateUser")] public System.Xml.XmlElement CancelUSer(string _UserID, string _Remarks) { if (UsersAuth.ValidateUser(AuthenticateUser.UserName, AuthenticateUser.Password) > 0) { //METHODS } } -------------------------- //Soap Header public class UserAuthenticateHeader : SoapHeader { public string UserName; public string Password; } //Class written for Authentication public class UsersAuth { static OracleConnection con; public UsersAuth() { con = new OracleConnection(WebConfigurationManager.ConnectionStrings["conString"].ToString()); } public static int ValidateUser(string _UserName, string _Password) { int Result = 0; using (OracleCommand cmd = new OracleCommand("SELECT COUNT(*) FROM USES WHERE UID=:UID AND PASSWORD=:PASSWORD", con)) { cmd.Parameters.AddWithValue(":UID", _UserName); cmd.Parameters.AddWithValue(":PASSWORD", _Password); con.Open(); Result = Convert.ToInt32(cmd.ExecuteScalar()); con.Close(); } return Result; } }
Now, When I call this from my program its throwing he ObjectReferenceNotSet to an instance of an object. I have set username, passsword and Headervalue for the method from the application. But its not hitting the "ValidateUser" Method.
Is there any way on which I can achieve this?