A DotNetNuke HTML Module Calling Visual Studio LightSwitch Using OData >DNN Software

Visual Studio LightSwitch provides the fastest and easiest method to create Line-Of-Business, Forms-Over-Data applications. Previously LightSwitch produced only Silverlight applications. Now with LightSwitch in Visual Studio 2012, LightSwitch now allows you to communicate with its security and business layer through OData. There’s an announced LightSwitch HTML Client currently in preview, but that uses JQuery Mobile, and therefore is targeted toward mobile devices such as tablets and cell phones. When one desires a full screen desktop HTML interface akin to a DotNetNuke module, OData provides the necessary communication.

What is OData?

Wireless Touch Switch Black 1 Gang 1 way Light Switch

OData is a protocol used to expose and consume data over the net. It uses a standard REST-like (representational state transfer) interface to speak, rather than the usual pre-defined application specific interfaces utilized by traditional web services. OData is a project created by Microsoft. The house page for the project is at: http://www.odata.org.

As described in the article: LightSwitch Architecture: OData (John Rivard) (http://blogs.msdn.com/b/lightswitch/archive/2012/03/22/lightswitch-architecture-odata.aspx), OData allows CRUD (Create, Read, Update, Delete) operations. This allows you to have full data interaction when you employ OData. As well as, OData provides a mechanism to question the info.

The appliance

Basic CRUD functionality is demonstrated in the instance application. It allows you to create new call records in the form at the underside, and so they display them in the grid at the highest. You possibly can update and delete the items in the grid (note: OData does support paging, but that was not implemented in this example).

LightSwitch has many features that allow you to easily implement business rules, security rules, and business types. In this example, the Phone Number business type, is about for the PhoneNumber field in the PhoneCall table in LightSwitch.

Without the need to write down a single line of code, the business type is enforced when calling the LightSwitch application through OData from DotNetNuke.

The Previous Application

We start with the applying created in the article: Easy DotNetNuke LightSwitch Deployment.

This article describes the steps needed to point the LightSwitch application to the DotNetNuke database and security when you publish it.

However, it produces a Silverlight application that runs in an IFrame in a DotNetNuke site. This actually provides the most effective user interface as far as performance, but if you must have an HTML page you possibly can create one using OData.

Creating The DotNetNuke OData Service Reference

If you create an OData module using server side code, you should create a service reference, and that creates a proxy class that you utilize to speak with the OData service. In a non-DotNetNuke project you’ll simply add the service reference. With a DotNetNuke module, you need to add the service reference in an external project in order that it creates an assembly (a .dll) that you would be able to package with the module when you progress your code from development to production.

To create a DotNetNuke module, you must arrange your DotNetNuke development environment. Use any method you might be comfortable with. We’re using the latest DotNetNuke 6 for this example, but listed here are some articles I created for DotNetNuke 4 and 5 that I still use:

DNN5 Development Environment – Windows 7 (using IIS)
Setting-up the Environment (using IIS)
Setting-up the Environment (without IIS)
Setting-up the event Environment on Windows Vista (or higher) (using IIS)

Note: for questions on developing DotNetNuke modules, see the next forums: http://www.dotnetnuke.com/Resources/Forums/GroupID/92.aspx.

In order for DotNetNuke to call LightSwitch, you need the ASP.NET OData libraries. You must have OData installed in your machine you probably have the newest service pacs, otherwise you may get it from here: http://msdn.microsoft.com/en-us/data/ee720179.


Open your DotNetNuke development site in Visual Studio 2010. If Visual Studio asks to upgrade the Target Framework to ASP.NET 4.0 say no. A DotNetNuke site should only be upgraded to ASP.NET 4.0 using the tactic described here: http://www.dotnetnuke.com/Resources/Blogs/EntryId/2619/Upgrading-DotNetNuke-to-ASP-NET-4-0.aspx (note: on the time of that post OData didn’t exist for ASP.NET 3.5. We’ll use ASP.NET 3.5 on this tutorial, however it may also work for any higher version).

Add a brand new project to the solution.

Add a brand new Class Library.

Delete the Class1.cs file that’s created.

Within the Properties for the project, set the Framework to three.5.

Select Add Reference.

Add a reference to System.Web.

Add a Service Reference.

The address to the LightSwitch OData service is the net address plus ApplicationData.svc (see Discover ways to Make OData Calls In LightSwitch 2011).

We enter that web address in the Address box in the Service Reference dialog.

When the authentication box pops up click Yes.

Because we have forms authentication enabled within the LightSwitch application, it requires us to enter a user name and password that is able to access the service. Because now we have the LightSwitch applications Web.config file configured to make use of the DotNetNuke site for authentication, we simply use a legitimate account from the DotNetNuke site.

Note: The authentication boxes will pop up again. It’s good to repeat the process twice.

The service can be discovered and show within the Services box. Enter a Namespace and click OK.

The service will probably be created.

Add a new class file to the project.

Use the following code:

This can be a partial class that will get the authentication cookie that the user gets when they log into DotNetNuke. The code creates and passes an authentication cookie on each OData call. This is finished because the cookie type that OData understands is just not the cookie type that the online browsers use (see: Calling LightSwitch 2011 OData Using Server Side Code).

Add a reference in the DotNetNuke project.

Add the reference to the OData proxy project.

The DotNetNuke module, to be created in the following step, will call this proxy to communicate with LightSwitch.

Also, add a reference in the DotNetNuke project to System.Data.Services.Client.

Note: This puts an entry in the web.config for “System.Data.Services.Client You would need to position that entry in the online.config of another DotNetNuke site you need to use with OData.


Leave a Reply

Your email address will not be published.