Apprenda does an excellent job at providing real value to the developer of a web based application. But what about those scenarios where a traditional desktop client makes more sense? By utilizing the Apprenda Remote API you gain access to all of the same features that developers creating web based applications would receive when communicating with their Apprenda deployed services. Let's take a small example from the Remote API Tutorial and show what logging into a Apprenda deployed service looks like and how the UserContext can then be utilized without any real work having to be done by the application developer.
From the example we have a service method call as follows:
public HelloDTO SayHello(HelloDTO data) { var result = new HelloDTO(); const string messageFormat = "Apprenda says hello {0}!"; result.Message = string.Format(messageFormat, UserContext.Instance.CurrentUser.FirstName); return result; }
All this service call is doing is saying hello back to the logged in user based on the UserContext of the currently logged in user. How can we set this context up from our remote application? The way we authenticate to the service endpoint using the Remote API is through the Session.EstablishSession() method. As part of the Remote API Tutorial I build a SessionManager class that makes it easy to setup and manage your session during the lifetime of the SessionManager object. This is what the SessionManager class looks like:
public class SessionManager : IDisposable
{
public Session Session { get; private set; }
public SessionManager(string user, string password)
{
this.LogOn(user, password);
}
public void LogOn(string user, string password)
{
this.Session = Session.EstablishSession(new Credentials(user, password));
if (this.Session == null)
{
throw new ApplicationException("Could not establish session.");
}
}
public void LogOff()
{
this.Session.ReleaseSession();
}
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
this.LogOff();
}
}
}
var session = new SessionManager(username, password);
var proxy = new HelloServiceProxy();
var response = proxy.SayHello(new HelloDTO {Message = "Hello Apprenda!"});
No need to create your own user management system, simply leverage what Apprenda provides for you. Feel free to post any questions or comments here or in the forums!
Comments