c# - $Metadata with WebAPi OData Attribute Routing Not Working -
i'm using odata attribute routing odata endpoint. here example of have:
[odatarouteprefix("profile")] public class profileodatacontroller : odatacontroller { [odataroute] [enablequery] public ihttpactionresult get() { var repo = new repositories.profilerepository(); return ok(repo.getprofiles()); } [odataroute("({key})")] [enablequery] public ihttpactionresult get([fromodatauri] string key) { var repo = new repositories.profilerepository(); var result = repo.getprofiles().singleordefault(x => x.id== key); if (result == null) return notfound(); return ok(result); } }
here set up:
config.mapodataserviceroute("odata", "odata", modelgenerator.getedmmodel());
here edmmodel generation:
public static iedmmodel generateedmmodel() { var builder = new odataconventionmodelbuilder(); builder.entityset<profile>("profile").entitytype.haskey(x => x.id); return builder.getedmmodel(); }
the urls /odata/profile
, /odata/profile('someid')
both work, when try access $metadata endpoint (/odata/$metadata#profile
), following error:
{"message":"no http resource found matches request uri 'http://****/odata/$metadata'.","messagedetail":"no type found matches controller named 'metadata'."}
do need create controller/action serving metadata? if so, how action implemented?
turns out had replacement of iassembliesresolver
.
i had implemented custom version provide component assemblies had implemented controllers in. however, error said, couldn't find controller named metadatacontroller
. turns out, odata implements one: system.web.odata.metadatacontroller
, provides $metadata
keyword.
since had implemented own iassembliesresolver
, system.web.odata
assembly wasn't being included, , $metadata
failed. once discovered this, , updated assembly resolver explicitly include odata assembly, works should.
Comments
Post a Comment