嗨朋友 自從過去一週以來,我一直在使用WCF。我寫了一些樣本,它包含2層,一個是業務層和一個DAL層。我想發送列表並希望返回列表。WCF中的轉換和返回列表
下面是代碼檢查糾正錯誤。
IEmployee.cs
[OperationContract]
List<outEmployee> CreateEmployeeDetails(inemployee InsertEmployee);
[DataContract]
public class inemployee
{
public string EmployeeID { get; set; }
public string EmployeeName { get; set; }
}
public class outEmailTemplate
{
public string EmployeeID { get; set; }
public string EmployeeName { get; set; }
}
Employee.svc.cs
public List<outEmployee> CreateEmployeeDetails(inemployee InsertEmployee)
{
EmployeeDac emp = new EmployeeDac();
return emp.InsertEmployeeDetails(InsertEmployee);
}
EmployeeDac.cs
public List<outEmployee> InsertEmailTemplate(inEmployee InsertEmp)
{
SqlConnection con = new SqlConnection(connectionstring);
SqlCommand cmd;
cmd = new SqlCommand("SP_InsertEmployee", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("employeename", SqlDbType.VarChar).Value = InsertEmp.Employeename;
con.Open();
string id = (string)cmd.ExecuteScalar();
con.Close();
List<inemployee> oet = new List<inemployee>();
oet.Add(id);
return oet;
}
任何人都可以糾正錯誤並重寫代碼。
這裏我想把列表返回給ui(silverlight)。
會發生什麼情況?你有錯誤嗎?如果是這樣:**究竟是什麼**?另外 - 你正在顯示一個'inemployee'和一個'outemailtemplate'類型,但是你的服務返回的類型'outemployee'卻不存在...... – 2011-04-26 13:55:15
在employeedac中的返回行中出錯。 – Raj 2011-04-26 13:57:16
Outemailtemplate是outemployee我忘記更改 – Raj 2011-04-26 13:58:51