Hi, when I try to test the web service LoginService.asmx (http://localhost/mono/LoginService.asmx), the method "Login" and "LogOut" go well, instead "TestLogin" give me only this message: --------------------- The remote server returned an error: (500) Internal Server Error. Object reference not set to an instance of an object ----------------------
If I try to test a client application (WebForm1LoginClient.aspx) that invoke the method "Login"of the LoginService.asmx I get this error: ------------------------------------ Server error in '/mono' application Description: Error processing request. Error Message: HTTP 500. Stack Trace: System.Web.Services.Protocols.SoapException: Object reference not set to an instance of an object in <0x00528> System.Web.Services.Protocols.SoapHttpClientProtocol:ReceiveResponse (System.Net.WebResponse,System.Web.Services.Protocols.SoapClientMessage,System.Web.Services.Protocols.SoapExtension[]) in <0x00080> (wrapper remoting-invoke-with-check) System.Web.Services.Protocols.SoapHttpClientProtocol:ReceiveResponse (System.Net.WebResponse,System.Web.Services.Protocols.SoapClientMessage,System.Web.Services.Protocols.SoapExtension[]) in <0x002a4> System.Web.Services.Protocols.SoapHttpClientProtocol:Invoke (string,object[]) in <0x0006f> (wrapper remoting-invoke-with-check) System.Web.Services.Protocols.SoapHttpClientProtocol:Invoke (string,object[]) in <0x00037> localhost.LoginService:TestLogin () in <0x0019d> LoginClient.WebForm1:ButtonLogin_Click (object,System.EventArgs) in <0x0006a> (wrapper delegate-invoke) System.MulticastDelegate:invoke_void_object_EventArgs (object,System.EventArgs) in <0x00090> System.Web.UI.WebControls.Button:OnClick (System.EventArgs) in <0x00058> System.Web.UI.WebControls.Button:System.Web.UI.IPostBackEventHandler.RaisePostBackEvent (string) in <0x00016> System.Web.UI.Page:RaisePostBackEvent (System.Web.UI.IPostBackEventHandler,string) in <0x0003a> System.Web.UI.Page:RaisePostBackEvents () in <0x002ab> System.Web.UI.Page:InternalProcessRequest () in <0x000c2> System.Web.UI.Page:ProcessRequest (System.Web.HttpContext) in <0x002e8> ExecuteHandlerState:Execute () in <0x00084> StateMachine:ExecuteState (System.Web.HttpApplication/IStateHandler,bool&) ------------------------------------ How to work with SessionState,(System.Web.SessionState) and System.Net? Thanks, Valentina. >Scrive Tom Larsen <[EMAIL PROTECTED]>: > > Exceptions are marshalled across application domains. What is the the > exception type, Exception.Message, Exception.StackTrace? > > Tom Larsen > > On Mon, 19 Jul 2004 [EMAIL PROTECTED] wrote: > > > > > > > Please help me! > > > > This example of Web Service run with success on Windows with VisualStudio > and > > IIS, but when I try to run on Linux (FC2) with Mono (Beta1),I get this > error : > > "The remote server returned an error: (500) Internal Server Error. > > Object reference not set to an instance of an object" > > > > > > The method that gives problem is TestLogin......Why? Which is the correct > > solution? > > > > WebService code is :LoginService.asmx.cs > > > > > > Thanks, > > > > Valentina. >
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Web; using System.Web.Services; using System.Data.Odbc; namespace LoginService { public class LoginService : System.Web.Services.WebService { public LoginService() { InitializeComponent(); } #region Component Designer generated code //Required by the Web Services Designer private IContainer components = null; /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { } /// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) { if(disposing && components != null) { components.Dispose(); } base.Dispose(disposing); } #endregion //############################################################################## //LOGIN //Metodo per il login dell'utente [WebMethod (EnableSession=true)] public bool Login( string LoginInserita, string PasswordInserita) { //connessione odbc al database mysql //su windows //OdbcConnection conn = new OdbcConnection("DRIVER={MySQL ODBC 3.51 Driver};"+"SERVER=localhost;"+"DATABASE=Login;"+"UID=root;"+"PASSWORD=rootpwd;"); //su linux OdbcConnection conn = new OdbcConnection("DRIVER=MySQL;SERVER=localhost;DATABASE=login;UID=root;PASSWORD=rootpwd;"); OdbcDataReader dbReader = null; conn.Open(); OdbcCommand cmd = conn.CreateCommand(); //controllo se la login e la password inserite dall'utente corrispondono ai dati mantenuti nel database "login" cmd.CommandText = "Select * from Login where Login='"+ LoginInserita+"' and Password='"+PasswordInserita+"'"; dbReader = cmd.ExecuteReader(); //se si mantengo la login dell'utente in una variabile di sessione ed il metodo torna "true" if(dbReader.Read()) { Session.Add("Login", LoginInserita); dbReader.Close(); conn.Close(); return true; } //atrimenti il metodo ritorna "false" password e login non sono corrette. else { dbReader.Close(); conn.Close(); return false; } } //############################################################################## //TEST LOGIN //Metodo che verifica il contenuto della variabile di Sessione "Login" [WebMethod (EnableSession=true)] public string TestLogin () { //se la variabile di sessione non è vuota, significa che l'utente si è logato, quindi recupero alcuni dati su di lui, ad esempio il "ruolo aziendale" if ((string)Session["Login"]!= null) { //Connessione al database su windows //OdbcConnection conn = new OdbcConnection("DRIVER={MySQL ODBC 3.51 Driver};"+"SERVER=localhost;"+"DATABASE=Login;"+"UID=root;"+"PASSWORD=rootpwd;"); //su linux OdbcConnection conn = new OdbcConnection("DRIVER=MySQL;SERVER=localhost;DATABASE=login;UID=root;PASSWORD=rootpwd;"); OdbcDataReader dbReader = null; conn.Open(); OdbcCommand cmd = conn.CreateCommand(); cmd.CommandText = "Select RuoloAziendale from Login where Login ='"+(string)Session["Login"]+"'"; dbReader = cmd.ExecuteReader(); if(dbReader.Read()) { Session.Add("Ruolo",(string)dbReader["RuoloAziendale"] ); dbReader.Close(); conn.Close(); } return (string)Session["Ruolo"]; } //se la variabile di sessione è vuota, l'utente non si è logato e quindi comunico un messaggio di errore else { return "need to login"; } } //############################################################################## //LOGOUT //Metodo per il logout [WebMethod (EnableSession=true)] public bool Logout() { //pulisco le variabili di sessione ed il metodo torna "false" Session.RemoveAll(); return false; } } }
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Net; namespace LoginClient { /// <summary> /// Summary description for WebForm1. /// </summary> public class WebForm1 : System.Web.UI.Page { protected System.Web.UI.WebControls.Label LabelRuolo; protected System.Web.UI.WebControls.Label LabelTest; protected System.Web.UI.WebControls.TextBox TextBoxLogin; protected System.Web.UI.WebControls.TextBox TextBoxPwd; protected System.Web.UI.WebControls.Label Label1; protected System.Web.UI.WebControls.Label Label2; protected System.Web.UI.WebControls.Button ButtonLogin; protected System.Web.UI.WebControls.Label LabelNome; protected System.Web.UI.WebControls.Label Label4; private localhost.LoginService MioServizio = new localhost.LoginService(); private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.ButtonLogin.Click += new System.EventHandler(this.ButtonLogin_Click); this.Load += new System.EventHandler(this.Page_Load); } #endregion private void ButtonLogin_Click(object sender, System.EventArgs e) { LabelTest.Text=""; System.Net.CookieContainer cookieJar = new System.Net.CookieContainer(); MioServizio.CookieContainer = cookieJar; //LabelTest.Text=MioServizio.Login(TextBoxLogin.Text, TextBoxPwd.Text).ToString(); MioServizio.Login(TextBoxLogin.Text, TextBoxPwd.Text).ToString(); Session.Add("Login", cookieJar); //LabelNome.Text= TextBoxLogin.Text; MioServizio.CookieContainer = (System.Net.CookieContainer)Session["Login"]; Session["LoginUtente"]=TextBoxLogin.Text; Session["RuoloAziendale"] = MioServizio.TestLogin(); if ((string)Session["RuoloAziendale"]=="need to login") { Session.RemoveAll(); LabelNome.Text=MioServizio.TestLogin(); } else { Response.Redirect("WebForm2LoginClient.aspx"); } } } }