Skip to main content

Mobile Services from Windows Azure - Data Store (part 2)

Part 1
When we need a backed to store data for a mobile application Windows Azure Mobile Services can be a great solution.
Let’s imagine that we need to develop a mobile application that need to store the GPS location of our client. For this purpose we can develop a complicated solution, with a backed that exposes this functionality as services. Also we will need an authentication mechanism that will add another layer of complexity.
All this functionalities are already supported by Windows Azure Mobile Services. In this blog post we will see how we can configure.
First step is to configure our Windows Azure account to have Mobile Services active. In this moment Mobile Services is in the preview, because of this before creating a Mobile Services you will need to sign up to this preview. From the new command of the portal you will find a link to the sign up page for the preview. The activation time period is very short. Each Mobile Services has a unique name, which will identify our service. At this step you will notify that a database needs to be attached to this service. You can use an existing one, or you can create a new one. This database will be used to store data.
After creating our own Mobile Service we will need to create a new table in the data section. Only the name of the table needs to be set. The columns will be automatically updated when you will insert entities in it.
Each new table that is created has some special permission that can be set. Each CRUD operation (Insert, Update, Delete, Read) can have a custom permissions set. We have 4 permissions available:
  • Anybody with the application key – anybody that has our application key can execute the command over the table
  • Everyone – anybody with our Mobile Services credetinals can execute the command over the table (even if the request don’t come from our application)
  • Only authenticate users – only users that were already authenticated in the application can execute the command over our table
  • Only scripts and admin – only scripts and administrators can execute the command over our table
In our case we will add a table named GPSLocation where the permissions will be set to “Only authenticate users”.
Next step is to create the entity that needs to be stored. In this moment Mobile Services can be used from iOS, Windows Phone and Windows Store (Windows 8) applications. We will use Windows Store in this example.
[DataContract]
public class Location
{
     int Id { get; set;}

     [DataMember]
     string Lat { get; set;}

     [DataMember]
     string Long { get; set;}
}
You notified that I decorated the class with DataContract. All entities that are saved need to be decorated with this attribute. This attributed is used when the entity is send to the Mobile Services and need to be serialized. Each property of our entity need to be a value type.
The Id property needs to be added to all items that are saved using Mobile Services. Each entity will be unique identified by this id. The auto-incrementation of this field will be made automatically by the system. Also we don’t need to add the “DataMember” attribute on this property. If we would need to references another entity that we will need to store the Id of the entity.
Mobile Services offer the build-in the mechanism that is used to consume data. The only thing that we need to have is the application url and application key. The application key is very important, because based on this people will be able to access your application.
You can use the same application key for an iOS and Windows Store application without any kind of problem. If your application key is compromised, a new one can be regenerated from the portal. In that moment you will have to make an update to your application with our new application key.
MobileServiceClient mobileService = new MobileServiceClient( [url], [applicationKey] );
This instance will be used to communicate with Mobile Services. All the request are made using HTTP/S and JSON. Yep, data are serialized in JSON format not in XML.
In the next post we will see how we can authenticate users to be able to add their GPS location. Remember, we set the rights to “Only authenticate users”. Because of this we need to be authenticating to make any kind of operations on our table. We need this because we don’t want to share locations between users.
Part 3

Comments

Popular posts from this blog

How to check in AngularJS if a service was register or not

There are cases when you need to check in a service or a controller was register in AngularJS.
For example a valid use case is when you have the same implementation running on multiple application. In this case, you may want to intercept the HTTP provider and add a custom step there. This step don’t needs to run on all the application, only in the one where the service exist and register.
A solution for this case would be to have a flag in the configuration that specify this. In the core you would have an IF that would check the value of this flag.
Another solution is to check if a specific service was register in AngularJS or not. If the service was register that you would execute your own logic.
To check if a service was register or not in AngularJS container you need to call the ‘has’ method of ‘inhector’. It will return TRUE if the service was register.
if ($injector.has('httpInterceptorService')) { $httpProvider.interceptors.push('httpInterceptorService&#…

ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded

Today blog post will be started with the following error when running DB tests on the CI machine:
threw exception: System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information. at System.Data.Entity.Infrastructure.DependencyResolution.ProviderServicesFactory.GetInstance(String providerTypeName, String providerInvariantName) This error happened only on the Continuous Integration machine. On the devs machines, everything has fine. The classic problem – on my machine it’s working. The CI has the following configuration:

TeamCity.NET 4.51EF 6.0.2VS2013
It seems that there …

Run native .NET application in Docker (.NET Framework 4.6.2)

Scope
The main scope of this post is to see how we can run a legacy application written in .NET Framework in Docker.

Context
First of all, let’s define what is a legacy application in our context. By a legacy application we understand an application that runs .NET Framework 3.5 or higher in a production environment where we don’t have any more the people or documentation that would help us to understand what is happening behind the scene.
In this scenarios, you might want to migrate the current solution from a standard environment to Docker. There are many advantages for such a migration, like:

Continuous DeploymentTestingIsolationSecurity at container levelVersioning ControlEnvironment Standardization
Until now, we didn’t had the possibility to run a .NET application in Docker. With .NET Core, there was support for .NET Core in Docker, but migration from a full .NET framework to .NET Core can be costly and even impossible. Not only because of lack of features, but also because once you…