我有一个 EF4 模型,其中包含一个我想从客户端调用的存储过程。 服务器代码如下所示:
[WebGet]
public IQueryable<SalesData> GetSalesReport(int reportType, int yr, int m, int d)
{
DateTime dt = new DateTime(yr, m, d);
return this.CurrentDataSource.RP_SalesReport(reportType, dt, dt).AsQueryable<SalesData>();
}
当使用 IE 使用 URL“http://localhost:12345/MyService.svc/GetSalesReport?reportType=1&yr=2009&m=4&d=2”调用此函数时,它会按预期工作。
在我的客户端应用程序中,我添加了对服务 (http://localhost:12345/MyService.svc) 的引用,但无论我尝试过,“GetSalesReport”功能都不会显示在对象浏览器中。 (正常的 EF 实体确实会显示在对象浏览器中)
所以我的问题是:如何从客户端调用这个函数?
根据客户端调用此函数的方式是否存在差异(我想从 Windows Phone 7 Silverlight 应用程序调用此函数,但现在我正在使用 WPF 测试客户端进行测试)。
最佳答案
实际上,ADO.NET DataTeam 似乎尚未实现用于从客户端调用 ServiceMethod 的 CodeGen。
所以我的问题的解决方案是在客户端编写以下代码:
// execute the service operation
Uri u = new Uri(string.Format("{0}/GetSalesReport?reportType={1}&yr={2}&m={3}&d={4}",
context.BaseUri, 1, 2009, 4, 2),UriKind.RelativeOrAbsolute);
var datas = context.Execute<SalesData>(u);
感谢 Gil Fink 撰写此博文:http://blogs.microsoft.co.il/blogs/gilf/archive/2008/11/14/consuming-data-services-service-operations.aspx
关于wcf - 从客户端调用 WCF DataService [WebGet] 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4659035/