November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
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
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.
Check out this link perhaps https://stackoverflow.com/questions/19969228/ensure-that-httpconfiguration-ensureinitialized ?
Do you call MapHttpAttributeRoutes explicitly anywhere in your code?
MapHttpAttributeRoutes does not get called anywhere in the code. it is just included in the web.config file.
I did just deploy this code this morning:
Yes - apply that code in pre-production and test if you have the same issue with production
I get this in the logs on the testserver:
System.Exception: Epi server api error, Runtime Error at EpiServerIntegration.MessageSending.MessageSender.HandleResponse(HttpResponseMessage response)
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
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(); } } }
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.
No, it's basically your code. I just made sure your code is executed after the attribute routes have been registered (Note the ModuleDependency)
Ok, so I tryied that, but still I get this error in Postman:
<h3>Exception details: </h3> HttpException: The controller for path '/episerverapi/commerce/catalogs' was not found or does not implement IController, Http status: 303 NotFound
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.
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.
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
When I set to episerver:serviceapi:maphttpattributeroutes="true" the site goes down, therefor I set it to false.
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.