开发者

Consume WCF Data Service resource dynamically

I have a WCF Data Service that exposes an Entity Framework database context and EntitySet like so,

public class DatabaseService : DataService<DatabaseContext>
{
    // This method is called only once to initialize service-wide policies.
    public st开发者_运维知识库atic void InitializeService(DataServiceConfiguration config)
    {

        // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
        // Examples:

        config.SetEntitySetAccessRule("People", EntitySetRights.AllRead);

        // config.SetServiceOperationAccessRule("MyServiceOperation", ServiceOperationRights.All);
        config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
    }
}

Is it possible to consume this service in a way that allows me to construct queries dynamically against the service using the full URI?

Ie. the URI I would be using is,

http://localhost:1353/DatabaseService.svc/People?$filter (my filter here)

I dont want any of my querying to be hard-coded, just dynamically invoked by changing the string-based URI.

Pretty sure its possible, but is the implementation simple or does it require alot of code, like a full dynamic proxy for the WCF service?

Ive only done stuff like this with plain SOAP services before.

EDIT

More specifically I want to be able to do something effectively like this,

IEnumerable<People> peopleResults = new DataServiceQuery("http://localhost:1353/DatabaseService.svc/People?$filter (my filter here)")

Where the results are populated right into my list without the client having to know anything except the full URI (including filters and all).


The DataServiceQuery class, once constructed for a type, has a RequestUri that you can set to customize the query. I don't know that it's the canonical usage but it would certainly work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜