Click here to Skip to main content
15,901,001 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I create a wcf service and i call it from the different project it shows me an error like
An existing connection was forcibly closed by the remote host

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 


code:

C#
if ((EmployeeType)dr["EmployeeType"] == EmployeeType.FullTimeEmployee)
                   {
                       MyEmployee = new FullTimeEmployee()
                      {
                          id = Convert.ToInt16(dr[0]),
                          name = dr["name"].ToString(),
                          gender = dr["Gender"].ToString(),
                          dob = Convert.ToDateTime(dr["DateOfBirth"]),
                       
                          AnnualSalary = Convert.ToInt16(dr["AnnualSalary"])
                      };
                   }
                   else
                   {
                       MyEmployee = new PartTimeEmployee
                      {
                          id = Convert.ToInt16(dr[0]),
                          name = dr["name"].ToString(),
                          gender = dr["Gender"].ToString(),
                          dob = Convert.ToDateTime(dr["DateOfBirth"]),
                          HourlyRate = Convert.ToInt16(dr["HourlyPay"]),
                       

                          HoursWorked = Convert.ToInt16(dr["HoursWorked"])
                      };

return MyEmployee;
Posted
Updated 7-May-14 5:08am
v3

1 solution

I resolved this by sending all the columns to employee class by just adding
Emptype = EmployeeType.PartTimeEmployee,

and return it to the method.

now my code is :

C#
while (dr.Read())
                {
                    //emps.id = Convert.ToInt16(dr[0]);
                    //emps.name=dr[1].ToString();
                    //emps.gender = dr[2].ToString();
                    //emps.dob = Convert.ToDateTime(dr[3]);
                    if ((EmployeeType)dr["EmployeeType"] == EmployeeType.FullTimeEmployee)
                    {
                        MyEmployee = new FullTimeEmployee()
                       {
                           id = Convert.ToInt16(dr[0]),
                           name = dr["name"].ToString(),
                           gender = dr["Gender"].ToString(),
                           dob = Convert.ToDateTime(dr["DateOfBirth"]),
                         Emptype = EmployeeType.FullTimeEmployee,//which i missed
                           AnnualSalary = Convert.ToInt16(dr["AnnualSalary"])
                       };
                    }
                    else
                    {
                        MyEmployee = new PartTimeEmployee
                       {
                           id = Convert.ToInt16(dr[0]),
                           name = dr["name"].ToString(),
                           gender = dr["Gender"].ToString(),
                           dob = Convert.ToDateTime(dr["DateOfBirth"]),
                           HourlyRate = Convert.ToInt16(dr["HourlyPay"]),
                         Emptype = EmployeeType.PartTimeEmployee,//Which i missed

                           HoursWorked = Convert.ToInt16(dr["HoursWorked"])
                       };
                    }
                }

            }
            return MyEmployee;

NOTE:I hope this error is caused by the missing the parameter of the class
 
Share this answer
 

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