I have a webservice that authenticates a client against clientcode, email and
password stored in mssql database. Now I am trying to consume it in my
iPhone app. I am trying to serialize the output returned by the web methods
and write to a file on the Personal folder on my machine. Then read a
certain node from it and show some form of welcome message when the
authentication is successful. Here is the code block which I am using, but I
am getting a NullReferenceEsxception: Object reference not set to an
instance of an object on the marked line. Can you guys tell me where I am
going wrong? Here ASTONAPPService is the name of the service that I have
added to my project. And GetLoginUser() is the exposed webmethod. Neither is
the directory being created nor is the xml file being written. I am just a
beginner, so I haven't got much clue either. 



if(ValidateControls ())
{
        ASTONAPPService.IPADService objipad=new
ASTONAPP.ASTONAPPService.IPADService();
        ASTONAPPService.BLL_User user=objipad.GetLoginUser(txtClientCode.Text,
txtEmail.Text, txtPassword.Text);
        if(user!=null)
        {
                System.Xml.Serialization.XmlSerializer xx=new 
XmlSerializer(user.GetType
());
                string
pathtowrite=Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                var dirName=Path.Combine (pathtowrite, "ASTON Repository");
                if(!Directory.Exists (dirName))
                {
                        Directory.CreateDirectory (dirName);
                }
                var filepath=Path.Combine (dirName, "BLL_User.xml");
                if(File.Exists (filepath))
                {
                        File.Delete (filepath);
                }
                TextWriter txtW=new StreamWriter(filepath);
                xx.Serialize (txtW, user);
                txtW.Close ();
                string clientcode=txtClientCode.Text;
                XDocument xdoc=XDocument.Load (filepath);
                var usrnm=xdoc.XPathSelectElement(String.Format
("BLL_User[DiyCode={0}]/UserName", clientcode));
                UIAlertView uvm=new UIAlertView("Notification", 
""+usrnm.ToString ()+"",
null, "OK", null);
                uvm.Show ();                                            
                this.ash=new AssessmentsHome();
                this.NavigationController.PushViewController (this.ash, true);
        }
        else
        {
                UIAlertView uvy=new UIAlertView("Notification", "Invalid 
Credentials!
Please try again!", null, "OK", null);  <--- this line *********
                uvy.Show ();
        }
}


What could be possibly wrong here? Can you spot any logical error in the
code block? Look forward to receiving some help on this matter.


--
View this message in context: 
http://monotouch.2284126.n4.nabble.com/XML-Serialization-and-writing-to-a-file-in-MOnoDevelop-with-C-tp4655459.html
Sent from the MonoTouch mailing list archive at Nabble.com.
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to