Inhalte aufrufen

Profilbild

Execution Flow of Smart store.net

executionFlow routeconfig webapiconfig applicationstart

  • Bitte melden Sie sich an, um eine Antwort zu verfassen.
3 Antworten zu diesem Thema

#1 pratiksha12

pratiksha12

    Newbie

  • Members
  • Punkt
  • 5 Beiträge

Geschrieben: 12 May 2016 - 12:28

hello , 

 

I was tring to create web api controller and return object for that ive written code but it only gives me error message because i have noticed that it is not calling webapiconfig. ive called it from application_start() in Global.aspx but it is not calling that too . can anyone tell me what is missing and how the flow of it going and how can i call my controller . my web api code and weapiconfig code is written bellow 

 

namespace SmartStore.Web
{
    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            config.MapHttpAttributeRoutes();
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "index", id = RouteParameter.Optional }
            );
 
            config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
        }
    }
}
 
 
namespace SmartStore.Web.WebApiController
{
    [WebApiAuthenticate]
    public class VINController : ApiController
    {
        private readonly IManufacturerInfoService _manufacturerInfoService;
        private readonly IModelInfoService _modelInfoService;
        private readonly IWMIInfoService _wmiInfoService;
 
        public VINController(IManufacturerInfoService manufacturerInfoService, IModelInfoService modelInfoService, IWMIInfoService wmiInfoService)
        {
            this._manufacturerInfoService = manufacturerInfoService;
            this._modelInfoService = modelInfoService;
            this._wmiInfoService = wmiInfoService;
        }
 
        public dynamic Get()
        {
            dynamic ManufacturesInfo = null;
            dynamic ModelInfos = null;
            dynamic WMIInfos = null;
            var ManufacturersInfo = _manufacturerInfoService.GetAllManufacturerInfo();
            var ModelInfo = _modelInfoService.getAllModelInfo();
            var WMIInfo = _wmiInfoService.getAllWMIInfo();
            foreach (var i in ManufacturersInfo)
            {
                ManufacturesInfo = from item in ManufacturersInfo
                                   select new
                                   {
                                       Id = item.Manufacture_code,
                                       Manufacturer = item.Manufacturer_Name
                                   };
            }
            foreach (var a in ModelInfo)
            {
                ModelInfos = from item in ModelInfo
                             select new
                             {
                                 Manu_Id = item.Manu_Id,
                                 Code = item.Model_Code,
                                 Model = item.Model_Name
                             };
            }
            WMIInfos = from item in WMIInfo
                       select new
                       {
                           initchar = item.Init_char,
                           id = item.Code,
                           Region = item.Region,
                           name = item.Name
                       };
            return new { ManufacturesInfo = ManufacturesInfo, ModelInfos = ModelInfos, WMIInfos = WMIInfos };
        }
    }
}
 

 



#2 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3801 Beiträge

Geschrieben: 12 May 2016 - 13:10

Please have a look at \Presentation\SmartStore.Web.Framework\WebApi\WebApiStartupTask.cs
how the SmartStore API is configured. The configuration should be placed in IStartupTask.Execute method.
 
I would suggest to use a different route template (e.g. "myapi/{controller}/{action}/{id}") because it's too near at the SmartStore API root "api/{version}/{controller}/{id}".

Marcus Gesing

Smartstore AG


#3 pratiksha12

pratiksha12

    Newbie

  • Members
  • Punkt
  • 5 Beiträge

Geschrieben: 13 May 2016 - 06:11

hii thank you for replying . but i did't get it . are you saying that i cannot use smartstore api root and i have to define my new root . and how can i configure my api controller . i have to make it in web folder as my requirement  is to host this webapi and access is outside the smartstore project. 



#4 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3801 Beiträge

Geschrieben: 13 May 2016 - 09:45

No, it was just a suggestion to use a different root template to avoid conflicts with the SmartStore API root. It is not a mandatory step.
 
Your question was about that your configuration was never executed and I recommend to place it in a IStartupTask.Execute method.
WebApiStartupTask.cs shows you how the SmartStore API configuration is set up.

Marcus Gesing

Smartstore AG