0

存储过程:

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]"

任何帮助,请

4

1 回答 1

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();

于 2013-11-25T21:27:48.803 回答