Click here to Skip to main content
15,888,022 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm new to both WP7 and web service. I created one login page in WP7 and created one
web service.I need to store user detail in access databse through web service. I successfully consumed web service in WP7 but it show error during runtime 'FaultException was unhandled' in the referance.cs file.
App_code/Services.cs (webservice code):
C#
[WebMethod]
    public string userDetail(int id, string uname, string pwd, int age, string gender, string place, string country)
    {       
        OleDbConnection con;
        OleDbCommand cmd;
        con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\Amma\\Documents\\UserDetail.accdb");
        con.Open();
        cmd = new OleDbCommand("insert into login(id,uname,pwd,age,gender,place,country)values(?,?,?,?,?,?,?)", con);
        cmd.Parameters.Add("?", id);
        cmd.Parameters.Add("?",uname);
        cmd.Parameters.Add("?", pwd);
        cmd.Parameters.Add("?", age);
        cmd.Parameters.Add("?", gender);
        cmd.Parameters.Add("?", place);
        cmd.Parameters.Add("?", country);
        cmd.ExecuteNonQuery();
        con.Close();
        return uname;
    }

MainPage.xaml.cs (WP7)
C#
string name, pwd, gender, place, country;
        int age, id = 0;
        private void BtnRegister_Click(object sender, RoutedEventArgs e)
        {
            ServiceReference1.ServiceSoapClient ws = new ServiceReference1.ServiceSoapClient();
            ws.userDetailCompleted += new EventHandler<userDetailCompletedEventArgs>(ws_userDetailCompletd);

            ws.userDetailAsync(id, name, pwd, age, gender, place, country);
        }
        void ws_userDetailCompletd(object sender,userDetailCompletedEventArgs e)
        {
            id = Convert.ToInt32(textBoxId.Text);
                   pwd = Convert.ToString(textBoxPwd.Text);
                   name = Convert.ToString(textBoxName.Text);
                   age = Convert.ToInt32(textBoxAge.Text);
          
                   if (radioBtnMale.IsChecked == true)
                   {
                       gender = "Male";
                   }
                   else
                       gender = "Female";
                   place = Convert.ToString(textBoxPlace.Text);
                   country = Convert.ToString(textBoxCountry.Text);          
                   MessageBox.Show("successfully Registered");
        }
referance.cs
C#
public Test.ServiceReference1.userDetailResponse EnduserDetail(System.IAsyncResult result) {
                object[] _args = new object[0];
                Test.ServiceReference1.userDetailResponse _result = ((Test.ServiceReference1.userDetailResponse)(base.EndInvoke("userDetail", _args, result)));
                return _result;
            }

Someone pls help me. thanks.
Posted
Updated 8-Feb-14 3:40am
v3

 
Share this answer
 
Comments
Sarath kumar.N 12-Feb-14 23:02pm    
I handled the exception using following code but the problem still remaining. help me pls.
try
{
id += 1;// Convert.ToInt32(textBoxId.Text);
pwd = Convert.ToString(textBoxPwd.Text);
name = Convert.ToString(textBoxName.Text);
age = Convert.ToInt32(textBoxAge.Text);

radioBtnMale.IsChecked = false;
if (radioBtnMale.IsChecked == true)
{
gender = "Male";
}
else
gender = "Female";
place = Convert.ToString(textBoxPlace.Text);
country = Convert.ToString(textBoxCountry.Text);
}
catch(FaultException FaultEx)
{
MessageBox.Show(FaultEx.Message);
}
Richard MacCutchan 13-Feb-14 3:15am    
Well you still have not told us what the exception was. However, there are a number of things wrong with the above code. You are using Convert.ToInt32 without checking the content of the textbox, you should use Int32.TryParse to validate the numbers. Also, why are you calling Convert.ToString(textBoxName.Text); when a Text field is already a string?
Sarath kumar.N 15-Feb-14 23:37pm    
same exception. finally i removed id but remaining FaultException was unhandled. Why it was?
Richard MacCutchan 16-Feb-14 3:15am    
Why are you still calling Convert.ToString on Text fields? You are also calling Convert.ToInt32 without verifying that the field is in fact a number string. You should be using Int32.TryParse.
I changed other statements but i can't change to Int32.TryParse. It thrown an error. "No overload for method 'TryParse' takes 1 arguments.

my code:
age=Int32.TryParse(textboxAge.text);
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 1-Mar-14 14:35pm    
Not an answer. Such posts are considered as abuse. Please remove it. Use comments instead.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900