Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Getting StartedGetting StartedWebAPI - Unable to locate a controller WebAPI - Unable to locate a controller
Previous
 
Next
New Post
2/8/2013 10:42 AM
 

I am running DNN7.02 and am trying to create a WebAPI service, following the example in this blog entry: http://www.dotnetnuke.com/Resources/Blogs/EntryId/3500/Getting-Started-with-Services-Framework-WebAPI-Edition.aspx.  I am writing mine in VB instead of C#, but otherwise I have followed the example exactly.  When I build the class library my dll shows up in the bin directory of my DNN site.  So far so good.  When I go to the URL that I believe should evoke my function I get an error message that says "Unable to locate a controller for http://dnndev.me/desktopmodules/MyServices/API/welcome/HelloWorld. Searched in namespaces: MyServices."  

Here is my code:

Imports System
Imports System.Net
Imports System.Net.Http
Imports System.Web.Http
Imports DotNetNuke.Web.Api

Namespace MyServices

    Public Class WelcomeController
        Inherits DnnApiController
        Implements IServiceRouteMapper

        <AllowAnonymous()> _
        <HttpGet()> _
        Public Function HelloWorld() As HttpResponseMessage
            Return Request.CreateResponse(HttpStatusCode.OK, "Hello World!")
        End Function

        Public Sub RegisterRoutes(mapRouteManager As IMapRoute) Implements IServiceRouteMapper.RegisterRoutes
            mapRouteManager.MapHttpRoute("MyServices", "default", "{controller}/{action}", New String() {"MyServices"})
        End Sub

    End Class

End Namespace

I am going to the URL http://dnndev.me/desktopmodules/MyServices/API/welcome/HelloWorld.

Any ideas what I am doing wrong?  

 
New Post
2/9/2013 1:36 AM
Accepted Answer 
Try removing the namespace from the class and then change the "Root Namespace" at the project level to MyServices

Ash Prasad
Director of Engineering
DNN Corp.
 
New Post
2/11/2013 10:38 AM
 

That fixed it!  You are the man.  Thank you so much.

 
New Post
2/11/2013 10:38 AM
 

That fixed it!  You are the man.  Thank you so much.

 
New Post
3/24/2013 3:26 PM
 

Hello!
I tried the example as a class project in VBnet too and it works after making the changes mentioned above, it works as expected .. thanks a lot for the tip with the Namespace!

Now I wanted to add a service to my own module that is based on the christoc VB2012 template for VB.
I added a class "WSController to the Project Directory, at the same level as view.ascx etc and added the code above

First when trying to call the Service from the browser i got a message about a missing dll
(Could not load file or assembly 'FiftyOne.Foundation' or one of its dependencies." ... I decided to solve it quick and very dirty and added a reference to that dll in dnns bin folder ...

Now when I try to access the Service by calling:
http://localhost/dnn7/DesktopModules/myModule/API/WS/HelloWorld
it produces the following Error:

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 

[NullReferenceException: Object reference not set to an instance of an object.] DotNetNuke.Common.Globals.get_Status() +158 DotNetNuke.HttpModules.RewriterUtils.OmitFromRewriteProcessing(String localPath) +55 DotNetNuke.HttpModules.RequestFilter.RequestFilterModule.FilterRequest(Object sender, EventArgs e) +205 System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +79 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +164 


please can anybody assist to sort out what the problem may be?

In the Project Properties I have already tried to remove the base Namespace (mmm.Modules.mmmModule1)  and adding it to the file "WSController" wrapping the Class "WSController" with no success.

The module is set up in localhost/dnn7/DesktopModules/mmmModule1
In this Folder there lies the Class "WSController.vb" with the following code:

Imports System
Imports System.Net
Imports System.Net.Http
Imports System.Web.Http
Imports DotNetNuke.Web.Api

Public Class WSController
    Inherits DnnApiController
    Implements IServiceRouteMapper

    <DnnAuthorize()> _
    <HttpGet()> _
    Public Function HelloWorld() As HttpResponseMessage
            Return Request.CreateResponse(HttpStatusCode.OK, "Hello World!")
    End Function

    ' Route Mapper
    Public Sub RegisterRoutes(mapRouteManager As IMapRoute) Implements IServiceRouteMapper.RegisterRoutes
        mapRouteManager.MapHttpRoute("mmmModule1", "default", "{controller}/{action}", New String() {"mmmModule1"})
    End Sub

End Class

Thanks in advance for any hint that puts me back on the road ;-)
kind regards
Don

 
Previous
 
Next
HomeHomeDevelopment and...Development and...Getting StartedGetting StartedWebAPI - Unable to locate a controller WebAPI - Unable to locate a controller


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out