How to access Azure Mobile Services project across different machines?

In this post, I’ll explain you how to access azure mobile services project across different machines which is really useful if you are working on different platforms like Mac or Windows OS at the same time.

I assume that you already have the knowledge to setup a project to use azure mobile services as backend in Visual Studio of your choice. I’m developing an application on my Mac OS and run Parallels to access Windows 8. The azure mobile services project by default works with IIS Express and Local DB if you are using a windows phone emulator or a browser as client on windows. As it’s a localhost request, there is also no need of authentication the requests as the backend then ignores this check.

Now to work on a cross platform application, I’d like to access this backend via REST API from other applications such as iOS or Android projects that I’m working on Mac side. To make this setup work, we need to change how this backend project is hosted on windows machine. Follow these steps:

    1. Right click on the project in Visual Studio, click on Properties and selected Web tab from the left.
    2. If you see the Servers area, you will that the default is set to IIS Express with a project Url. Change this to Local IIS. You will notice that the Url has changed now to something like http://localhost/YourBackendProjectName (default port is 80). This means we will not be able to use Visual Studio’s out of the box features that makes working with hosting, local db in IIS Express very easy and also you don’t have to be an Administrator. However, as such this option is no more in use, we need to have IIS installed and you must be an administrator or have all the required rights to create the Virtual Directory. This can be done by using the button next to Project Url.
    3. When you try to save this setup in Properties, it will give you a prompt that you are going to use a local IIS and it’s recommended to use SQL Server Express with this IIS. However, to use local db that was already created with backend, click No for this prompt.
    4. Open IIS Manager and refresh the site that has the new virtual directory. In order to make this local db visible to our new hosting setup we need to create a new Application pool. Then go to Advanced Settings and change the Identity to your user account in the settings. This is good for development purpose only and make sure that your account has rights to access the database (or an Administrator).

  1. Also, make sure that Load User Profile setting is set to true that is just below the Identity setting. This will load the user profile whenever it is required.
  2. Click on the IIS Server node in the tree view that you see on the left and select Configuration Editor. Choose system.applicationHost/applicationPools from the Section dropdown & open the App Pools collection. Selected your app pool and look for Process Model > setProfileEnvironment property in the Properties below. Set this to True for this setup to work.
  3. Make sure your hosted app is using the same application for which you followed the steps above.
  4. If you browse the application it should run on http://localhost/YourBackendProjectName. Make sure you have the firewall settings setup to allow access to port 80 so that other apps from Mac can talk to this project.
  5. As such your backend app is not hosted as localhost, you now need to decorate your API controllers or actions with Authorize level of Anonymous as the backend will now perform the authentication check. After applying this change, build your project.
  6. Now you should be able to access backend from a browser on Mac either by http://{fullSystemQualifiedName/YourBackendProjectName} or http://{ipAddressforWindows}/YourBackendProjectName and you should see the Azure blue screen with a smiley.

There are other ways to accomplish this either by choosing to use sql-server express database or changing the host config file which may be reset when you open your Visual Studio next time. I’ve found that the above setup works very well for development scenario.



Siddharth Pandey

Siddharth Pandey is a Software Engineer with thorough hands-on commercial experience & exposure to building enterprise applications using Agile methodologies. Siddharth specializes in building, managing on-premise, cloud based real-time standard, single page web applications (SPAs). He has successfully delivered applications in health-care, finance, insurance, e-commerce sectors for major brands in the UK. Other than programming, he also has experience of managing teams, trainer, actively contributing to the IT community by sharing his knowledge using Stack Overflow, personal website & video tutorials.

You may also like...

Advertisment ad adsense adlogger