Sir i m developing WP 8.1 app where i m utilizing WCF service but when i run my app it gives me the following exception: "An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in System.Windows.ni.dll Additional information: Exception has been thrown by the target of an invocation". here is my IService1.cs method:
[OperationContract] string Insert_ChallanDetails(Insert_Challan challan);
here is my service.svc.cs implementation:
public string Insert_ChallanDetails(Insert_Challan challan) { string Message; SqlConnection conn = new SqlConnection(connection_string); conn.Open(); SqlCommand cmd = new SqlCommand("INSERT INTO Voilation (Name,Voilation_place,Home_address,Licence_No,Place_issue,Reg_no,Offence1,Offence2,Offence3,Penalty1,Penalty2,Penalty3,Rs)VALUES (@Name,@Voilation_Place,@Address,@Licence_No,@Location,@Registration_No,@Offence_Code_1,@Offence_Code_2,@Offence_Code_3,@Penalty_1,@Penalty_2,@Penalty_3,@Total)", conn); cmd.Parameters.Add("@Name",System.Data.SqlDbType.Text).Value=challan.NAME; cmd.Parameters.Add("@Voilation_Place", System.Data.SqlDbType.Text).Value = challan.VIOLATION_PALCE; cmd.Parameters.Add("@Address", System.Data.SqlDbType.Text).Value = challan.ADDRESS; cmd.Parameters.Add("@Licence_No", System.Data.SqlDbType.Text).Value = challan.LICENCE_NO; cmd.Parameters.Add("@Location",System.Data.SqlDbType.Text).Value=challan.LOCATION; cmd.Parameters.Add("@Registration_No", System.Data.SqlDbType.Text).Value = challan.REGISTRATION_NO; cmd.Parameters.Add("@Offence_Code_1",System.Data.SqlDbType.Text).Value=challan.OFFENCE_CODE_1; cmd.Parameters.Add("@Offence_Code_2", System.Data.SqlDbType.Text).Value = challan.OFFENCE_CODE_2; cmd.Parameters.Add("@Offence_Code_3", System.Data.SqlDbType.Text).Value = challan.OFFENCE_CODE_3; cmd.Parameters.Add("@Penalty_1", System.Data.SqlDbType.Money).Value = challan.PENALTY_1; cmd.Parameters.Add("@Penalty_2", System.Data.SqlDbType.Money).Value = challan.PENALTY_2; cmd.Parameters.Add("@Penalty_3", System.Data.SqlDbType.Money).Value = challan.PENALTY_3; cmd.Parameters.Add("@Total", System.Data.SqlDbType.Money).Value = challan.TOTAL; int result = cmd.ExecuteNonQuery(); if(result==1) { Message = challan.NAME + "Challan Inserted Sucessfully"; } else { Message = challan.NAME + "Challan Could not be Inserted"; } return Message; }
and here is my button click event in wp8:
private void submit_button_Click(object sender, RoutedEventArgs e) { try { Insert_Challan challanInfo = new Insert_Challan(); challanInfo.NAME = Name_Text.Text; challanInfo.LOCATION = Location_text.Text; challanInfo.ADDRESS = address_text.Text; challanInfo.LICENCE_NO = Licence_text.Text; challanInfo.VIOLATION_PALCE = IssuePlace_text.Text; challanInfo.REGISTRATION_NO = RegNo_text.Text; challanInfo.OFFENCE_CODE_1 = code1_text.Text; challanInfo.OFFENCE_CODE_2 = code2_text.Text; challanInfo.OFFENCE_CODE_3 = code3_text.Text; challanInfo.PENALTY_1 = decimal.Parse(Penalty_1.Text); challanInfo.PENALTY_2 = decimal.Parse(Penalty_2.Text); challanInfo.PENALTY_3 = decimal.Parse(Penalty_3.Text); challanInfo.TOTAL = decimal.Parse(total_text.Text); try { service.Insert_ChallanDetailsCompleted += new EventHandler<Insert_ChallanDetailsCompletedEventArgs>(service_Insert_ChallanDetailsCompleted); service.Insert_ChallanDetailsAsync(challanInfo); } catch(Exception ex) { MessageBox.Show(ex+""); } //service.Insert_ChallanDetailsCompleted += new EventHandler<Insert_ChallanDetailsCompletedEventArgs>(service_Insert_ChallanDetailsCompleted); } catch(Exception ex) { throw (ex); } }