Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

OData with Module Zero #717


User avatar
0
robertfitch created

Hi, I purchased an ASP.NET Zero project and have followed these instructions: <a class="postlink" href="http://aspnetboilerplate.com/Pages/Documents/OData-Integration">http://aspnetboilerplate.com/Pages/Docu ... ntegration</a> to try OData with an entity ("Contact") I created, but when I try: GET: <a class="postlink" href="https://localhost:44305/odata/Contacts">https://localhost:44305/odata/Contacts</a> I only get the standard response "oops you're lost".

So I am wondering if the RouteConfig included in the ASP.NET Zero Web module applications is interfering with the automatic OData registration in the WebApi module.

Here is my Controller:

public class ContactsController : AbpODataEntityController&lt;Contact, Guid&gt;
{
    public ContactsController(IRepository&lt;Contact, Guid&gt; repository)
    : base(repository)
    {
    }
}

And here is my WebApi module:

/// &lt;summary&gt;
/// Web API layer of the application.
/// &lt;/summary&gt;
[DependsOn(typeof(AbpWebApiODataModule), typeof(CosmosMoonApplicationModule))]
public class CosmosMoonWebApiModule : AbpModule
{
    public override void PreInitialize()
    {
        var builder = Configuration.Modules.AbpWebApiOData().ODataModelBuilder;

        //Configure OData entities here...
        builder.EntitySet&lt;Contact&gt;("Contacts");
    }

    public override void Initialize()
    {
        IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());

        //Automatically creates Web API controllers for all application services of the application
        DynamicApiControllerBuilder
            .ForAll&lt;IApplicationService&gt;(typeof(CosmosMoonApplicationModule).Assembly, "app")
            .Build();

        Configuration.Modules.AbpWebApi().HttpConfiguration.Filters.Add(new HostAuthenticationFilter("Bearer"));
    }
    public override void PostInitialize()
    {
        Configuration.Modules.AbpWebApi().HttpConfiguration.EnsureInitialized();
    }
}

Any ideas? Thank you, RobertFitch


2 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    Thank you for pointing that. I found the problem. MVC default controller/action route conflict with odata route. I will make a fix for it in ABP 0.8. For now, as a workaround, move your Route code from Initialize of your WebModule to PostInitialize.

    A working branch: <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero/commit/18f091274b9190e598bc6dc763866abafe9811a9">https://github.com/aspnetzero/aspnet-ze ... bafe9811a9</a>

    NOTE: This is also valid for open source ABP templates.

  • User Avatar
    0
    robertfitch created

    Thanks for your quick help, the workaround is now running! regards