WCF代理类不生成对象参数

时间:2016-10-25 17:07:42

标签: c# wcf

当我在WCF服务中定义以下操作合同时: -

public void SaveEmployee(EmployeeInfo employee)
{

    string cs = ConfigurationManager.ConnectionStrings["EMS"].ConnectionString;

    using (SqlConnection con = new SqlConnection(cs))
    {
        SqlCommand cmd = new SqlCommand("spSaveEmployee",con);
        cmd.CommandType = CommandType.StoredProcedure;
        SqlParameter parameterId = new SqlParameter() { ParameterName = "@Id", Value = employee.Id };
        cmd.Parameters.Add(parameterId);
        SqlParameter parameterName = new SqlParameter() { ParameterName = "@Name", Value = employee.Name };
        cmd.Parameters.Add(parameterName);
        SqlParameter parameterGender = new SqlParameter() { ParameterName = "@Gender", Value = employee.Gender };
        cmd.Parameters.Add(parameterGender);
        SqlParameter parameterDOB = new SqlParameter() { ParameterName = "@DateOfBirth", Value = employee.DOB };
        cmd.Parameters.Add(parameterDOB);
        SqlParameter parameterType = new SqlParameter() { ParameterName = "@EmployeeType", Value = employee.Type };
        cmd.Parameters.Add(parameterType);

        if (employee.Type == EmployeeType.FullTimeEmployee)
        {
            SqlParameter parameterAnnualSalary = new SqlParameter() { ParameterName = "@AnnualSalary", Value = employee.AnnualSalary };
            cmd.Parameters.Add(parameterAnnualSalary);
        }
        else
        {
            SqlParameter parameterHourlyPay = new SqlParameter() { ParameterName = "@HourlyPay", Value = employee.HourlyPay };
            cmd.Parameters.Add(parameterHourlyPay);
            SqlParameter parameterHoursWorked = new SqlParameter() { ParameterName = "@HoursWorked", Value = employee.HoursWorked };
            cmd.Parameters.Add(parameterHoursWorked);
        }

        con.Open();
        cmd.ExecuteNonQuery();
    }
}

生成的代理方法如下: -

 public void SaveEmployee(int Id, string Name, string Gender, DateTime DOB, EmployeeType Type, int AnnualSalary, int HourlyPay, int HoursWorked);

虽然,它应该是: -

 public void SaveEmployee(Employee employee);

有人能告诉我这背后的原因吗?

0 个答案:

没有答案