我试图从我的WCF数据服务返回一个自定义类.我的自定义类是:
[DataServiceKey("ID")]
public class Applist {
public int ID { get; set; }
public string Name { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我的数据服务看起来像:
public static void InitializeService(IDataServiceConfiguration config)
{
config.RegisterKnownType(typeof(Applist));
config.SetEntitySetAccessRule("*", EntitySetRights.All);
config.SetServiceOperationAccessRule("GetApplications", ServiceOperationRights.AllRead);
}
[WebGet]
public IQueryable<Applist> GetApplications() {
var result = (from p in this.CurrentDataSource.Applications
orderby p.ApplicationName
group p by p.ApplicationName into g
select new Applist { ID = g.Min(p => p.id), Name = g.Key });
return result.AsQueryable();
}
Run Code Online (Sandbox Code Playgroud)
但是,当我运行该服务时,它给了我一个错误:
Request Error Request Error The server encountered an error …Run Code Online (Sandbox Code Playgroud) 有谁知道它是否可能,如果有的话,通过linqpad调用服务操作的语法是什么?
另外,当我使用linqpad调用它时,我可以使用命名参数吗?那将是很好的b/c我在服务操作中有很多参数,我不想指定每一个.
谢谢!
我正在尝试构建一个包含大量实体和一些服务操作的ADO.NET数据服务.一方面,我创建了一个ASP.NET Web应用程序,其中包含ADO.NET实体数据模型和ADO.NET数据服务.另一方面,我创建了第二个ASP.NET Web应用程序,它具有对数据服务的服务引用.
实体很顺利,我可以使用LINQ来检索我想要的数据:
TestEntities entities = new TestEntities(
new Uri("http://localhost/service/service.svc"));
var query = from customer in entities.Customers
where customer.ID == 1234
select customer;
query.ToList();
Run Code Online (Sandbox Code Playgroud)
这有效.但是,通过服务操作检索信息完全不适合我.数据服务端代码:
public static void InitializeService(IDataServiceConfiguration config) {
config.SetEntitySetAccessRule("*", EntitySetRights.All);
config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
}
[WebInvoke]
public IQueryable<Customer> GetSomeCustomers() {
TestEntities entities = new TestEntities();
return from customer in entities.Customers
where customer.ID > 0 && customer.ID < 20
select customer;
}
Run Code Online (Sandbox Code Playgroud)
当我将服务引用添加到我的客户端项目时,Visual Studio没有接受任何服务操作.我知道我可以通过构造的URI和DataServiceContext对象或TestEntities对象的BeginExecute方法(在这种情况下)或类似的东西来访问它们,但这不是我想要的.
我想要的是使用LINQ来检查服务操作的返回数据.这可能吗?它应该是,对吧?