Define the following services (With the v3 and the v4 assemblies):
```
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.Routes.MapODataServiceRoute("odataV4", "odataV4", GetV4Model());
config.Routes.MapODataRoute("odataV3", "odataV3", GetV3Model());
}
private static ODataEdmV3.IEdmModel GetV3Model()
{
ODataV3.Builder.ODataConventionModelBuilder builder = new ODataV3.Builder.ODataConventionModelBuilder();
builder.EntitySet<Customer>("Customers");
return builder.GetEdmModel();
}
private static IEdmModel GetV4Model()
{
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<Customer>("Customers");
return builder.GetEdmModel();
}
```
Query the v3 metadata
http://localhost:19564/odataV3/$metadata
Result:
> <Error>
<Message>An error has occurred.</Message>
<ExceptionMessage>
Multiple types were found that match the controller named 'ODataMetadata'. This can happen if the route that services this request ('odataV3/{*odataPath}') found multiple controllers defined with the same name but differing namespaces, which is not supported. The request for 'ODataMetadata' has found the following matching controllers: System.Web.OData.ODataMetadataController System.Web.Http.OData.ODataMetadataController
</ExceptionMessage>
<ExceptionType>System.InvalidOperationException</ExceptionType>
<StackTrace>
at System.Web.Http.Dispatcher.DefaultHttpControllerSelector.SelectController(HttpRequestMessage request) at System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken) at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__0.MoveNext()
</StackTrace>
</Error>
Comments: Yup. I've already got a fix for this one locally. Did it a while ago but forgot it was needed.
```
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.Routes.MapODataServiceRoute("odataV4", "odataV4", GetV4Model());
config.Routes.MapODataRoute("odataV3", "odataV3", GetV3Model());
}
private static ODataEdmV3.IEdmModel GetV3Model()
{
ODataV3.Builder.ODataConventionModelBuilder builder = new ODataV3.Builder.ODataConventionModelBuilder();
builder.EntitySet<Customer>("Customers");
return builder.GetEdmModel();
}
private static IEdmModel GetV4Model()
{
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<Customer>("Customers");
return builder.GetEdmModel();
}
```
Query the v3 metadata
http://localhost:19564/odataV3/$metadata
Result:
> <Error>
<Message>An error has occurred.</Message>
<ExceptionMessage>
Multiple types were found that match the controller named 'ODataMetadata'. This can happen if the route that services this request ('odataV3/{*odataPath}') found multiple controllers defined with the same name but differing namespaces, which is not supported. The request for 'ODataMetadata' has found the following matching controllers: System.Web.OData.ODataMetadataController System.Web.Http.OData.ODataMetadataController
</ExceptionMessage>
<ExceptionType>System.InvalidOperationException</ExceptionType>
<StackTrace>
at System.Web.Http.Dispatcher.DefaultHttpControllerSelector.SelectController(HttpRequestMessage request) at System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken) at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__0.MoveNext()
</StackTrace>
</Error>
Comments: Yup. I've already got a fix for this one locally. Did it a while ago but forgot it was needed.