3

我刚刚阅读了“在 ADO.NET 数据服务中注入自定义逻辑”,我的下一个问题是,如何让您的[WebGet]方法显示在客户端代理类中?当然,我可以直接(以 REST 方式)调用它,WebClient但我认为 ADO.NET 数据服务中的强类型功能会自动神奇地“隐藏”我。

所以在这里我们有:

public class MyService : DataService<MyDataSource>
{
    // This method is called only once to initialize service-wide policies.
    public static void InitializeService(IDataServiceConfiguration config)
    {
        config.SetEntitySetAccessRule("Customers", EntitySetRights.AllRead);
        config.SetServiceOperationAccessRule("CustomersInCity", ServiceOperationRights.All);
    }

    [WebGet]
    public IQueryable<MyDataSource.Customers> CustomersInCity(string city)
    {
        return from c in this.CurrentDataSource.Customers
               where c.City == city
               select c;
    } 

}

我怎样才能CustomersInCity()出现在我的客户端类定义中?

4

1 回答 1

1

当您在浏览器中看到您的 Odata 时,您将看到链接 ... 例如http://localhost:1234/odataService.svc

只需在您的方法的链接后写下您的方法名称,它将是这样的......

http://localhost:1234/odataService.svc/CustomersInCity?city= "伦敦"

于 2011-11-07T13:51:08.093 回答