London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!

Episerver API

Vote:
 

I get this error in my logs in our production environment. What might have happened?

The controller for path '/episerverapi/commerce/entries' was not found or does not implement IController.

Yesterday I used Postman to fetch nodes and commerce content and I got responses. Today I get a Http 404 when doing the same calls with a new generated token bearer. 

During this last week the API seems to been working on and of. Sometimes I get a feel that it is not there.

#197001
Edited, Sep 19, 2018 12:13
Vote:
 

It sounds like you need to make sure this is in your web.config/appSettings: episerver:serviceapi:maphttpattributeroutes needs to be true. Otherwise ServiceAPi will not map the routes and cause the problem you see 

#197005
Sep 19, 2018 13:15
Vote:
 

Ok. Yesterday this was set to false and I could fetch data from the service api. When I now follow your advice I recieve this in return from Postman:

{
    "Message": "An error has occurred.",
    "ExceptionMessage": "The object has not yet been initialized. Ensure that HttpConfiguration.EnsureInitialized() is called in the application's startup code after all other initialization code.",
    "ExceptionType": "System.InvalidOperationException",
    "StackTrace": "   at System.Web.Http.Routing.RouteCollectionRoute.get_SubRoutes()\r\n   at System.Web.Http.Routing.RouteCollectionRoute.GetRouteData(String virtualPathRoot, HttpRequestMessage request)\r\n   at System.Web.Http.WebHost.Routing.HttpWebRoute.GetRouteData(HttpContextBase httpContext)"
}

That made the whole site go down.

#197008
Edited, Sep 19, 2018 13:28
Vote:
 

Check out this link perhaps https://stackoverflow.com/questions/19969228/ensure-that-httpconfiguration-ensureinitialized ?

Do you call MapHttpAttributeRoutes explicitly anywhere in your code?

#197009
Sep 19, 2018 13:30
Vote:
 

MapHttpAttributeRoutes does not get called anywhere in the code. it is just included in the web.config file.

#197011
Sep 19, 2018 13:38
Vote:
 

I did just deploy this code this morning:

    [InitializableModule]
    [ModuleDependency(typeof(FrameworkInitialization))]
    public class WebApiConfig : IInitializableModule
    {
        public void Initialize(InitializationEngine context)
        {
            // Enable Web API routing
            GlobalConfiguration.Configure(config =>
            {
                config.Routes.MapHttpRoute(name: "DefaultEpiApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional });
            });
        }
         public void Uninitialize(InitializationEngine context)
        {
            throw new NotImplementedException();
        }
    }
Can it be that which ruin all?
#197012
Sep 19, 2018 13:41
Vote:
 

Couldn't you test this in pre-production to make sure? 

#197013
Sep 19, 2018 13:52
Vote:
 

What do you recommend me to test? The code that i deployed?

#197014
Sep 19, 2018 13:54
Vote:
 

Yes - apply that code in pre-production and test if you have the same issue with production 

#197015
Sep 19, 2018 13:55
Vote:
 

OK, but I don't think I can reach pre-production with Postman.

#197016
Sep 19, 2018 13:56
Vote:
 

I get this in the logs on the testserver:

System.Exception: Epi server api error, Runtime Error at EpiServerIntegration.MessageSending.MessageSender.HandleResponse(HttpResponseMessage response)

#197017
Edited, Sep 19, 2018 14:10
Vote:
 

there seem to be the same error as in production.

#197018
Sep 19, 2018 14:24
Vote:
 

So there is reason to believe that new code was causing problem. I'm not an "route" expert but it seems that by registering convention routes you forgo all attribute route 

#197019
Sep 19, 2018 14:32
Vote:
 

I had a bit of time to play around and it seems your new initialization module will register your convention route before the attribute routes are registered - causing the problem. Did not drill down the framework code to see why, but this seems to be working for me:

using System;
using System.Web.Http;
using EPiServer.Framework;
using EPiServer.Framework.Initialization;
using EPiServer.ServiceApi.Commerce;

namespace EPiServer.Commerce.Sample
{
    [InitializableModule]
    [ModuleDependency(typeof(IntegrationInitialization))]
    public class WebApiConfig : IInitializableModule
    {
        public void Initialize(InitializationEngine context)
        {
            // Enable Web API routing
            GlobalConfiguration.Configure(config =>
            {
                config.Routes.MapHttpRoute(name: "DefaultEpiApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional });
            });
        }
        public void Uninitialize(InitializationEngine context)
        {
            throw new NotImplementedException();
        }
    }
}
#197027
Sep 19, 2018 15:27
Vote:
 

Interesting. The code I added were not meant to have any impact on episerver service API. I was adding to benefit using of a web api controller in my site. It looks like to me that your code above is aiming to write a routing for the service API. Sorry for missleading you in that case.

#197029
Sep 19, 2018 16:13
Vote:
 

No, it's basically your code. I just made sure your code is executed after the attribute routes have been registered (Note the ModuleDependency)

#197030
Edited, Sep 19, 2018 16:15
Vote:
 

Ok, so I tryied that, but still I get this error in Postman:

 <h3>Exception details: </h3> HttpException: The controller for path &#39;/episerverapi/commerce/catalogs&#39; was not found or does not implement IController, Http status: 303 NotFound

#197032
Edited, Sep 19, 2018 16:35
Vote:
 

You made sure the above setting was set to true in web.config?

#197033
Sep 19, 2018 17:17
Vote:
 

Yes I did. In the test environment I still get this error when I push products to the API:

2018-09-20 09:06:28,695 [82] ERROR EPiServer.Global: 1.2.5 Unhandled exception in ASP.NET
System.Web.HttpException (0x80004005): The controller for path '/episerverapi/commerce/entries' was not found or does not implement IController.

#197048
Sep 20, 2018 9:11
Vote:
 

It's time to contact developer support service then :)

#197049
Sep 20, 2018 9:29
Vote:
 

Ok. Thanks Quan! I will do so.

#197052
Sep 20, 2018 9:39
Vote:
 

I added the following row just before the confi.Routes.MapHttpRoute(...

config.MapHttpAttributeRoutes();

in the GlobalConfiguration.Configre(config....

and deployed it to production. After that I was able to retrieve data from episerverapi again, and the Http 404 disapeared.

#197059
Sep 20, 2018 13:16
Vote:
 

That is not possible. with episerver:serviceapi:maphttpattributeroutes is true, ServiceAPi would call that already. Calling one more time would throw A route named 'MS_attributerouteWebApi' is already in the route collection. Route names must be unique. Parameter name: name exception

#197060
Sep 20, 2018 13:20
Vote:
 

When I set to episerver:serviceapi:maphttpattributeroutes="true" the site goes down, therefor I set it to false.

#197062
Sep 20, 2018 15:01
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.