usman shaheen
usman shaheen

Reputation: 3766

Get Entities Names from WCF Data Services Request

How can I get Entities (tables) names when intercepting incoming OData Get Request in OnStartProcessingRequest() method? for example: I want to get MusicCollection and Genre as Entity names from following oData URI

http://dataserver.com/service.svc/MusicCollection[SomeSong]/Genre

Upvotes: 1

Views: 167

Answers (1)

MikeReed - MSFT
MikeReed - MSFT

Reputation: 61

This is a perfect use for the OdataUriParser! It's in active, incremental, development as we speak, with filter and orderby parsers being available currently, and much more to come as we finish development. We haven't released the part of the parser which will handle your specific scenario (its still in active development), but there is an experimental version (on which the official version is based) that you could use in the mean time. Take a look at the OData contrib library here: http://nuget.org/packages/Microsoft.Data.OData.Contrib. Specifically, something like this:

  Uri requestUri  = new Uri("http://dataserver.com/service.svc/MusicCollection(SomeSong)/Genre");
  Uri baseUri = new Uri("http://dataserver.com/service.svc/")
  SyntacticTree parsedUri = SyntacticTree.ParseUri(requestUri, baseUri);

The resulting SyntacticTree will have your uri broken down into QueryTokens, just walk the tree to find the path you're looking for!

Upvotes: 1

Related Questions