我创建了一个WCF服务,用于将数据从客户端插入到数据库中。现在我正在通过将虚拟数据插入数据库来从控制台应用程序测试我的服务。但问题是我得到一个未处理的异常,它在图片中显示了堆栈跟踪:
以下是我的客户端控制台应用程序的代码:
static void Main(string[] args)
{
int id = 0;
string name = "ali";
string fname = "musa";
string cnic = "61101-3927067-5";
string postaladdress = "G-13";
ServiceClient s = new ServiceClient();
ServiceReference1.Employee e = new ServiceReference1.Employee();
e.EmployeeID = id;
e.EmployeeName = name;
e.EmployeeFatherName = fname;
e.Cnic = cnic;
e.PostalAddress = postaladdress;
s.insertEmployeePortfolio(e);
//ServiceData d =new ServiceData();
//d= s.TestConnection();
Console.WriteLine("Haha");
}
以下是WCF服务中的服务类代码:
public class Service : IService
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConStr"].ToString());
public string insertEmployeePortfolio(Employee emp)
{
SqlCommand scmd = new SqlCommand("insertEmployeeRecord", conn);
scmd.CommandType = CommandType.StoredProcedure;
scmd.Parameters.AddWithValue("@employeeName",emp.EmployeeName);
scmd.Parameters.AddWithValue("@employeeFatherName", emp.EmployeeFatherName);
scmd.Parameters.AddWithValue("@cnic", emp.Cnic);
scmd.Parameters.AddWithValue("@postalAddress", emp.PostalAddress);
conn.Open();
string result=scmd.ExecuteScalar().ToString();
conn.Close();
return result;
}
}
请帮帮我。提前谢谢。