存储过程:
ALTER PROCEDURE [dbo].[TestDataSP]
AS
BEGIN
SELECT FirstName
FROM Employees
WHERE EmployeeID = 7
END
TaskTrackerDataService.cs
[WebGet]
public String GetEmployeeName()
{
TaskTracker_EDM.TaskTrackerEntities ctx = new TaskTracker_EDM.TaskTrackerEntities();
return ctx.TestDataSP().FirstOrDefault();
}
我有一个存储过程,我可以从Web上调用它
http:localhost:2402/TaskTrackerDataService.svc/GetEmployeeName
它将返回员工姓名
<GetEmployeeName xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices">Keko88</GetEmployeeName>
当我尝试从我的WPF项目中调用存储过程时
TaskTrackerDataService.TaskTrackerEntities ctxDSvc = new TaskTrackerDataService.TaskTrackerEntities(new Uri("http:localhost:2402/TaskTrackerDataService.svc"));
String emps1 = ctxDSvc.Execute<String>(new Uri("http:localhost:2402/TaskTrackerDataService.svc/GetEmployeeName")).ToString();
Console.WriteLine(string.Format("ID: {0} ==== ==== ==== ", emps1));
它总是返回
"System.Data.Services.Client.QueryOperationResponse`1[System.String]"
请帮助
答案 0 :(得分:0)
错误是 总是返回“System.Data.Services.Client.QueryOperationResponse`1 [System.String]”
所以添加单个,它将返回字符串结果
String emps1 = ctxDSvc.Execute(new Uri(“http:localhost:2402 / TaskTrackerDataService.svc / GetEmployeeName”))。Single();
错误的是 String emps1 = ctxDSvc.Execute(new Uri(“http:localhost:2402 / TaskTrackerDataService.svc / GetEmployeeName”))。ToString();