【发布时间】:2016-10-19 20:25:37
【问题描述】:
我有一个连接到 wcf 服务的 MVC 应用程序,我正在尝试制作一个包含依赖于其他任务的任务的待办事项列表应用程序,到目前为止我没有运气,但我已经构建了一个存储proc,我现在从我的 WCF 服务调用它并向客户端返回响应。
目前,客户端在1分钟无响应时出现以下错误;
"The request channel timed out while waiting for a reply after 00:01:00. Increase the timeout value passed to the call to Request or increase the SendTimeout value on the Binding. The time allotted to this operation may have been a portion of a longer timeout."
我的 WCF 服务上的代码如下所示;
public DataTable GetAllDependantTasks(string id)
{
DataTable dt = new DataTable();
try
{
using (SqlConnection conn = new SqlConnection())
using (SqlCommand com = new SqlCommand())
{
conn.ConnectionString = ConfigurationManager.ConnectionStrings["ToDoDatabase"].ConnectionString;
com.Connection = conn;
com.CommandText = "usp_GetAllDependantTaskInfoByID";
com.CommandType = CommandType.StoredProcedure;
com.Parameters.Add(new SqlParameter("@id", id));
conn.Open();
SqlDataReader returnvalue = com.ExecuteReader();
if (returnvalue.HasRows)
{
//List<DataRow> items = new List<DataRow>();
dt.Load(returnvalue);
// foreach (DataRow row in dt.Rows)
// {
// items.Add(row);
//}
return dt;
}
else
{
throw new RowNotInTableException();
}
}
}
catch (Exception ex)
{
//TODO: Write error to log
return new DataTable();
}
}
我在前端使用 ASPX 页面,违规代码如下所示;
private void LoadTasks()
{
// get the todo list items
ToDoService.ToDoServiceClient client = new ToDoService.ToDoServiceClient();
try
{
// List<ToDoService.ToDoItemContract> toDoItems = client.GetToDoItems("").ToList();
List<string> Items = new List<string>();
foreach(var row in client.GetAllDependantTasks("").Rows)
{
Items.Add(row.ToString());
}
dlTasks.DataSource = Items;
dlTasks.DataBind();
client.Close();
}
catch (Exception ex)
{
// TODO: Log error
client.Abort();
}
}
谁能指出我正确的方向?我想在前端用现有任务加上它们所依赖的任务填充我的数据列表,我试图从我的 wcf 服务返回一个数据表以将其绑定到列表,但它似乎不喜欢它!
提前感谢:)
【问题讨论】:
-
你独立测试过存储过程吗?它运行吗?同时发布您的 WCF 接口和合同。