问题
The title explains the requirement. Is it possible to expose multiple endpoints in single project?
Something like:
- http://localhost:8000/svc1/$metadata
- http://localhost:8000/svc2/$metadata
- http://localhost:8000/svc3/$metadata
Because I need to divide functionality into multiple components. Can anyone help me?
UPDATE
Currently I'm using below code to create and expose Odata service.
public void Configuration(IAppBuilder app)
{
HttpConfiguration config = new HttpConfiguration();
ConfigureRoute(config);
ConfigureGlobalFilters(config);
HttpServer server = new HttpServer();
ODataBatchHandler batchHandler = new DefaultODataBatchHandler(server);
config.MapODataServiceRoute("Odata", "Odata", GenerateEdmModel(), batchHandler);
...
config.EnsureInitialized();
}
private IEdmModel GenerateEdmModel()
{
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.Namespace = "ServiceA";
builder.ContainerName = "DefaultContainer";
builder.EntitySet<Permission>("ApplicationPermissions");
return builder.GetEdmModel();
}
I would like to expose separate services for each component (under different namespaces?).
回答1:
The following line should be the one you care about:
config.MapODataServiceRoute("Odata", "Odata", GenerateEdmModel(), batchHandler);
The second string parameter is the routePrefix
, which means currently you're probably hitting http://yourhost.com/Odata/$metadata. If you simply create another mapping with a different prefix value (e.g. Odata2
) you'd be able to make calls against http://yourhost.com/Odata/$metadata AND http://yourhost.com/Odata2/$metadata. You'll probably want to give them both a unique routeName as well though (the first string parameter), and you'll probably want to provide a different model as well so the two services will actually be different :).
来源:https://stackoverflow.com/questions/43966261/is-it-possible-to-expose-multiple-odata-v4-endpoints-in-asp-net-webapi-project