Step 2–Augmented Reality, Windows 8, and Cloud Computing–How to implement with real code

Title Description Link
Augmented Reality applications need a Web Service Back-End. Here is a 90-Day No obligation, totally free offer to use Windows Azure as your web service for Windows 8 Clients. You get: Compute / 750 small compute hours per month, Web sites / 10 web sites, Mobile services / 10 mobile services, Relational database / 1 SQL database, SQL reporting / 100 hours per month, Storage / 35GB with 50,000,000 storage transactions, Bandwidth / unlimited inbound & 25GB outbound, CDN / 20GB outbound with 500,000 transactions, Cache / 128MB, Service bus / 1,500 relay hours and 500,000 messages /Redirect2.ashx?CR_CC=200114759image
Step 0: What we will build. Augmented Reality, Windows 8, and Cloud Computing–How to implement with real code High level introduction to our finished application. /11/05/step-0-what-we-will-build- augmented-reality-windows-8-and-cloud-computing-how-to-implement-with-real-code.aspx#
Step 1–Augmented Reality, Windows 8, and Cloud Computing–How to implement with real code Introduction. What is Augmented Reality step-1-augmented-reality-windows-8-and-cloud-computing- how-to-implement-with-real-code.aspx#
Step 2–Augmented Reality, Windows 8, and Cloud Computing–How to implement with real code Building the first part of our Azure back-end. step-2-augmented-reality-windows-8-and- cloud-computing-how-to-implement-with-real-code.aspx#
Step 3–Augmented Reality, Windows 8, and Cloud Computing–How to implement with real code (Implementing the Cloud Back-End) This post provides all source code and explanation for the Azure back-end. This is the back-end for the augmented reality Windows 8 Client. /step-3-augmented-reality-windows-8-and-cloud-computing-how- to-implement-with-real-code-implementing-the-cloud-back-end.aspx#
Step 4–Augmented Reality, Windows 8, and Cloud Computing–How to implement with real code ... This post provides all source code and explanation for the Windows 8 Client (Augmented Reality Demo). The augmented reality Windows 8 Client calls into the Azure back-end described in step 3 above. step-4-augmented-reality-windows-8-and-cloud-computing-how-to-implement-with-real-code-implementing-the- windows-8-client.aspx#
Source Code - Web Service Back End This is the Windows Azure Project that Windows 8 Clients call into
Source Code - Windows 8 Client This is the Augmented Reality Windows 8 Client
The purpose of this post is to create the starting project for the web service backend.

Later, we will create the augmented reality Windows 8 client. 001

  1. Let's start with the cloud back-end.
  2. The mobile application will send the Azure Cloud Application GPS coordinates.
  3. The Cloud Application will use the coordinates to do a lookup at or to find more information about those coordinates.
    • For example, it can lookup the city and neighborhood.
  4. The Cloud application will return this data back to the client for display on the screen, overlaying the photo.

Notice that we are selecting an MVC Web API application. 002


  1. It is important to understand WHY I am choosing an MVC Web API project type.
  2. There are basically two options to build the web services project:
    • Use Windows Communication Foundation - WCF -, or
    • Use ASP.NET Web API, which is included with MVC version 4.
  3. Exposing services via WCF is also easy to do.
  4. But for this specific scenario we will use the newer, more modern approach that ASP.NET Web API brings to the table, truly embracing HTTP concepts (URIs and verbs).
  5. The MVC Framework allows us to create services that use more easily use some HTTP features, such as request/response headers, along with hypermedia constructs.
  6. Both projects can be tested on a single machine during development.
  7. Watch the following 1.5 minute video to see how to create a cloud-based MVC4 application.

Understanding Role Types for a Windows Azure Project - What the options mean 003
  1. ASP.NET Web Role
    • This is old school web forms.
    • This is a very well-established pattern for creating modern web applications.
    • There is a well established eco-system of tools, documentation and resources.
    • But it doesn't lend itself to unit testing.
    • It doesn't have a clear separation of code-behind and markup.
    • Many developers have moved on to ASP.NET MVC, described next.
  2. ASP.NET MVC3/4 Web Role (what we choose in these posts)
    • This is the popular and powerful framework from Microsoft.
    • It is a web application framework that implements the model-view-controller (MVC) pattern.
    • It also provides the ability throu the Web API to create REST-based web services. -We will choose this option.
    • Can do unit testing and has clear separation of concerns.
  3. WCF Service Web Role
    • The Windows Communication Foundation (or WCF) is a runtime and a set of APIs in the .NET Framework for building connected, service-oriented applications.
    • It has been used heavily for SOA-type applications, but has given ground to the Web API as REST-based architectures grew in popularity.
    • This is a perfectly acceptable solution, and the only solution, if you need to support many advanced Web services (WS) standards such as WS-Addressing, WS-ReliableMessaging and WS-Security.
    • With subsequent versions of the NET Framework 4.0, WCF also provides RSS Syndication Services, WS-Discovery, routing and better support for REST services.
  4. Worker Role
    • So far we have been taking about web roles. Web roles, by default, include Internet Information Server (IIS) inside of a Windows Server OS inside a VM, running on one physical core.
    • Worker roles are the same thing as web roles, except there is no IIS.
    • This allows cloud-based applications to run background processes, typically reading messages placed in queues by web roles.
    • Worker roles can leverage Windows Azure Storage, just like web roles.
  5. Cache Worker Role
    • Windows Azure Caching supports the ability to host Caching services on Windows Azure roles.
    • In this model, the cache can join memory resources to form a cache cluster.
    • This private cache cluster is available only to the roles within the same deployment.
    • Your application is the only consumer of the cache.
    • There are no predefined quotas or throttling.
    • Physical capacity (memory and other physical resources) is the only limiting factor.
    • Other features include named caches, regions, tagging, high availability, local cache with notifications, and greater API symmetry with Microsoft AppFabric 1.1 for Windows Server.

Understanding VisualController is a key starting point 004
  1. VisualController.cs is a file we need to modify.
  2. It contains the code that will execute when the Windows 8 client submits an HTTP request against the web service.
    • This HTTP request will include GPS data.
  3. This is where we will add some of our code to return the JSON data required by the Windows 8 application.
  4. The ValuesController class is generated by Visual Studio, and it inherits from ApiController, which returns data that is serialized and sent to the client, automatically in JSON format.
  5. We will test this file before modifying it. We need to learn how to call methods inside of VisualController.cs
123456789101112131415161718192021222324252627282930 public class ValuesController : ApiController{    // GET api/values    public IEnumerable<string> Get()    {        return new string[] { "value1", "value2" };    }    // GET api/values/5    public string Get(int id)    {        return "value";    }    // POST api/values    public void Post(string value)    {    }    // PUT api/values/5    public void Put(int id, string value)    {    }    // DELETE api/values/5    public void Delete(int id)    {    }}
Key Http Support Note that the methods above - Get(), Post(), Put(), Delete(). These methods map to specific CRUD operations and HTTP verbs executed by the Windows 8 application. Because it is based on REST, any client capable of http can call into these methods.
Automatic routing of web requests This is the magic of the ASP.NET Web API framework: it automatically routes the HTTP verbs used by the client directly to the methods defined in the VisualController class, minimizing potential programming mistakes.
Our LocationWebService project is ready to run right now. The methods in the ValuesController class are self-documenting. Note that the Get() method in the code below gets called when the client issues the HTTP verb get using the following URL: port differs from system to system. If we deploy to a data center, this port is not relevant. The port matters only if you run your project locally on your development machine)
We will call he Get() method from a Windows 8 client
1234     public IEnumerable<string> Get()    {        return new string[] { "value1", "value2" };    }

Note the video which shows us exactly how to call into a web service method 006
  1. Let us now use a browser to test our web service.
  2. Any browser can be used for this purpose.
  3. To test the Web Service from a browser, perform the following steps:
  4. In Visual Studio, click on the Debug menu and choose Start Debugging.
  5. This will start the various emulators to allow us to run our application on our local dev machine.
    • There is a Compute Emulator
      • Runs our MVC WebAPI app
    • There is a Storage Emulator
      • We are not using storage today for this app
  6. You should see the screen above.
    • Notice the web address of
      • That is port 81 on my machine (yours may differ)
  7. We can call the get() method by simply issuing the following url
      • This will trigger the ASP.NET Web API application to send the two strings:
        • value1 and value2
  8. Watch the video that illustrates this application running and returning value1 and value2
  9. We just ran a simple intro sample before we do the real work.
  10. Now should starting to see that we can call into the cloud application quite easily. We just need to use a URL from a Windows 8 Application.
    • We can pass parameters and receive data back.
      • The data we pass will be GPS coordinates.
      • The data we get back will be location information, such as neighborhood, city, etc.
  11. Conclusion
    1. We have successfully tested an MVC Web API based cloud project.
    2. The next step is to enhance it to call another web service to get location information based on GPS coordinates
      1. This is Step 3
    3. Question
      1. Should I keep doing quick videos? Are they helpful?
      2. No voice yet. Pretty self-explanatory what I'm doing.