Question

I need to use functionality available with the Lightswitch ApplicationServerContext available in the 2012 version of Lightswitch in the Silverlight version of the client part of the application.

The only examples I've been able to find so far show the HTML client of Asp.net pages etc

I have tried creating the ApplicationServerContext in the Silverlight client using

ServerApplicationContext context = ServerApplicationContext.CreateContext();

but I get the error "The name 'ServerApplicationContext' does not exist in the current context"

Is it possible to use ApplicationServerContext in the Silverlight client and if so how?

Thanks

Mark

Was it helpful?

Solution

The ServerApplicationContext is intended to give access to the custom Business Logic on the server. Before this the only way to communicate with the server middle tier was via oData. Using the ServerApplicationContext it is possible to extend your Lightswitch Application serverside with other technologies such as ASP. NET MVC, ASP.NET WEBFORMS and ASP. NET WEBAPI.

It is not possible to acces the ServerApplicationContext from the Silverlight Client because

  • the Silverlight Client communicates with the Server via oData
  • the Silverlight Client is a portable dll, the Server is a .net framework dll, you cannot reference a .net framework dll from a portable library dll
  • the Client and the Server share business logic code such as the entities through sharing code techniques and T4
  • almost the same api that the ServerApplicationContext exposes is accessible to the Silverlight Client through the clientside available objects Application and Dataworkspace

If you want to access server side functionality from the Client you could:

  • use operation table techniques, which uses a lightswitch table to pass parameters to the server and invoke your server side code in the _inserting eventhandler of the entity related to the operation table. This is, for example, the only way to implement functionality such as Sending Emails, because Silverlight portable library does not support Email functionality
  • Extend your Lightswitch Server with ASP. NET MVC, ASP.NET Webforms or ASP.NET Web Api and in conjunction with the ServerApplicationContext code your server side functionality. After that you could invoke that functionality from the Silverlight Client using normal HTTP requests

Since Microsoft stopped developing Lightswitch and browsers which support plugins such as java, flash and silverlight are deprecated (the new Windows 10 Edge browser does not support any plug ins, silverlight included...) the way of preserving your development investments in lightswitch applications could be to deploy only the lightswitch server, expose your use cases through current asp.net techonologies and develop a new desktop client using a current techonology (such as WPF) that connects to the lightswitch middle tier through OData or other webservices that you could expose.

Hope this helps.

OTHER TIPS

Sadly

MSDN informs we cant use the ServerApplicationContext from the client http://msdn.microsoft.com/en-us/library/dn781266.aspx Member of: Microsoft.LightSwitch.Framework.Server

Alternatives

You can access server from preprocess queries. http://msdn.microsoft.com/en-us/library/ff852040.aspx

Personaly i use a hubconnection with SignalR. http://blog.pragmaswitch.com/?p=607

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top