Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing Azure Emulator from Another Device

I Have two different projects:

  1. Windows Phone 8 Application, which I am running on a real, physical development device.
  2. Azure Cloud service, which contains one simple WebRole endpoint that contains a ASP.NET MVC WebAPI.

My goal is simple:
Use the WP8 Application running from a real device, to access (using HTTPClient) the WebAPI controller while it is deployed to the Azure Emulator.

What DO work is:

  1. The application can successfully communicate with the WebApi when it is deployed on Azure Cloud.
  2. The application can successfully communicate with the WebApi when it is hosted locally on IIS Express (Without Azure), and the IIS Express settings are changed following this article.

As far as I understand, the problem is that the Azure Emulator is configured to listen on IP address 127.0.0.1, which is not accessible from outside the localhost domain.

I found this post that offers a solution to this exact problem, but trying to follow it results in an Unknown Exception while trying to deploy to Azure Emulator.

Is it really impossible to locally test WP8 application that communicates with Azure Cloud Service?

like image 961
Liel Avatar asked Nov 30 '22 01:11

Liel


2 Answers

I figured out how it is possible to have a Phone Emulator or an attached physical Windows Phone device communicating with the Azure Emulator.

For other developers struggling with the same requirement, here are the steps required for it to work:

Assumptions:

  1. You know the IP address of the hosting machine.
  2. No Firewall is blocking the access
  3. Shut down IIS and Azure Emulators and restart them after configuration changes

Azure Compute Emulator:

  1. Open "C:\Program Files\Microsoft SDKs\Windows Azure\Emulator\devfabric\DevFC.exe.config" for editing.
  2. Set "VipPoolStartIPAddress" and "VipPoolEndIPAddress" to your hosting machine IP (e.g. 192.168.1.100)

Azure Storage Emulator:

  1. Open both "C:\Program Files\Microsoft SDKs\Windows Azure\Emulator\devstore\DSServiceLDB.exe.config" and "C:\Program Files\Microsoft SDKs\Windows Azure\Emulator\devstore\DSServiceSQL.exe.config" for editing.
  2. Set the services section in both of the files to use hosting IP.
  3. Configure the Storage Connection String in the "Role" settings (instead of default Windows Azure storage emulator setting):
    • Right click on the Role (under "Roles" folder in the solution explorer) to enter it's Properties page. Click on Settings tab. Make sure you edit the Local settings (Select it on Service Configuration selection box).
    • Edit the Connection String for the storage
    • Manually enter credentials
    • Account name and account key are written under accounts section in DSServiceSQL.exe.config
    • Specify custom endpoints, with your hosting IP.

enter image description here

Enjoy!

like image 193
Liel Avatar answered Dec 06 '22 12:12

Liel


You don't need any external app to do this. Try port forwarding using the following:

  1. Run your application in Azure emulator and then find out its IP and Port by right-clicking the IIS Express icon in the system tray (say 127.0.0.1:81)

  2. Now choose a port to listen to (say 8088) and forward its incoming requests to your application by simply executing the below command in an elevated command prompt:

    netsh interface portproxy add v4tov4 listenport=8088 connectaddress=127.0.0.1 connectport=81 protocol=tcp

  3. If the firewall is running and your chosen port is blocked, then open the port (8088 in this example) by adding an inbound rule to Windows Firewall.

Now browse using your Computer IP, like 192.168.0.100:8088, and now you should be able to access your application. And this can be used through your WP or Cordova (mobile) app to test locally. Hope this helps.

(If you want to remove the port forwarding, then just use the delete switch of the netsh interface portproxy command.)

like image 21
Santosh Avatar answered Dec 06 '22 13:12

Santosh