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...DNN Platform (o...DNN Platform (o...Calling WebAPI Service From Another AppCalling WebAPI Service From Another App
Previous
 
Next
New Post
9/7/2013 10:44 PM
 

When I call a DNN WebAPI service that has an AllowAnonymousAttribute from another application it works just fine. Actually it's as simple as can be to get back fully typed objects!

However, I am unable to use the DNN authentication attribute successfully.

Here is the code in question (I'm sorry, I cant see how to format it):

Code:

Option Infer On

Imports System.Collections

Imports System.Collections.Generic

Imports System.Linq

Imports System.Net

Imports System.Net.Http

Imports System.Web.Http

Imports DotNetNuke.Entities.Portals

Imports DotNetNuke.Entities.Users

Imports DotNetNuke.Security.Roles

Imports DotNetNuke.Web.Api

Namespace MyServices

Public Class RoleSubscriptionController

Inherits DnnApiController

<allowanonymous,> _</allowanonymous,>

Public Function GetTestData() As HttpResponseMessage

Dim result As New List(Of RoleDTO)

result.Add(New RoleDTO With {.RoleID = 11, .Subscribed = True})

result.Add(New RoleDTO With {.RoleID = 12, .Subscribed = True})

result.Add(New RoleDTO With {.RoleID = 13, .Subscribed = False})

Return Request.CreateResponse(HttpStatusCode.OK, result)

End Function

#Region "Nested type: RoleDTO"

Public Class RoleDTO

Public Property RoleID() As Integer

Public Property Subscribed() As Boolean

End Class

#End Region

End Class

End Namespace

[code]

 

And the simple consuming code:

 

[code]

Imports System.Net.Http

Imports System.Net.Http.Headers

Public Class OwnersClubClient

Private _Client As HttpClient

Private _Handler As New HttpClientHandler

Public Async Sub Test()

_Handler.Credentials = New System.Net.NetworkCredential("admin", "password")

_Client = New HttpClient(_Handler)

Dim response = Await _Client.GetAsync("http://www.dnndev.me/DesktopModules/MyServices/API/RoleSubScription/GetTestData")

response.EnsureSuccessStatusCode() ' Throw on error code.

Dim products As IEnumerable(Of RoleDTO) = Await response.Content.ReadAsAsync(Of IEnumerable(Of RoleDTO))()

Debug.Print(products.Count)

End Sub

Public Class RoleDTO

Public Property RoleID() As Integer

Public Property Subscribed() As Boolean

End Class

End Class

 

 
Previous
 
Next
HomeHomeDevelopment and...Development and...DNN Platform (o...DNN Platform (o...Calling WebAPI Service From Another AppCalling WebAPI Service From Another App


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