asp.net-web-apidotnetnukedotnetnuke-moduledotnetnuke-7dotnetnuke-6

DotNetNuke7:-Web Api is not triggering on call


I have implemented a module using Angular Js and TypeScript in DotNetNuke7 where i have implemented my all Input Forms and js in a web project named as customerNew and than added a Web APi into a another project named as CustomerNewController which is having my methods but when i hit the URL from my Web Project to Api.It doesn't processed.I have implemented a route mapper as well but still not able get success.

My Route Mapper Class is Given Below:-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DotNetNuke.Web.Api;
using System.Web.UI.WebControls;


namespace CustomerNewController
{
    class RouteMapper : IServiceRouteMapper
    {
        public void RegisterRoutes(IMapRoute mapRouteManager)
        {
            mapRouteManager.MapHttpRoute("CustomerNewController", "default", "{controller}/{action}",
                new[] { "CustomerNewController" });
        }
    }
}

Here is my WebApi

using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using System.Collections;
using System.Web.UI;
using System.Xml.Serialization;
using DotNetNuke.Entities.Users;
using System.Web.Services;
using DotNetNuke.Web.Api;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules.Communications;
using DotNetNuke.Entities.Modules;    

namespace CustomerNewController
{
    public class CreateController : DnnApiController
    {
        [AllowAnonymous]
        [HttpGet]
        public HttpResponseMessage HelloWorld()
        {
            return Request.CreateResponse(HttpStatusCode.OK, "Hello World!");
        }
}}

My URL

http://localhost/dnn7/DesktopModules/CustomerNewController/Api/Create/HelloWorld

Here is my folder structure Folder Structure


Solution

  • An example of my WebAPI GET method:

    [DnnExceptionFilter]
    public class AuthorController : DnnApiController
    {
        #region Public RPC Methods
    
        [HttpGet]
        [AllowAnonymous]
        public HttpResponseMessage GetAllAuthors()
        {
            var lstAuthors = AuthorRepository.GetAllAuthors();
            return Request.CreateResponse(HttpStatusCode.OK, lstAuthors);
        }
    
        [HttpGet]
        [AllowAnonymous]
        public HttpResponseMessage GetAlphabet()
        {
            var lstAuthors = AuthorRepository.GetAlphabet();
            return Request.CreateResponse(HttpStatusCode.OK, lstAuthors);
        }
    
        #endregion
    }
    

    Service route mapper example (only need to do this once):

    public class ServiceRouteMapper : IServiceRouteMapper
    {
        #region IServiceRouteMapper Implementation
    
        public void RegisterRoutes(IMapRoute mapRouteManager)
        {
             mapRouteManager.MapHttpRoute("ATKV.Commerce", "default", "{controller}/{action}", new[] { "ATKV.Commerce.Services" });
        }
    
        #endregion
    }
    

    Calling code:

    // Service Paths
        var servicesFramework = opts.servicesFramework;
        var servicePath = servicesFramework.getServiceRoot('ATKV.Commerce') + 'Author/';
    // Bind data
        $.ajax({
            type: "GET",
            cache: false,
            url: servicePath + "GetAllAuthors",
            beforeSend: servicesFramework.setModuleHeaders
        }).done(function (authors) {
            if (typeof authors !== "undefined" && authors != null) {
                var viewModel = new MasterViewModel(authors);
                ko.applyBindings(viewModel, document.getElementById($(containerElement).attr('id')));
            } else {
                displayMessage("An error occurred", "dnnFormError");
            }
        }).fail(function (xhr, status) {
            displayMessage(status, "dnnFormError");
            return null;
        });