4

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?

Liel
  • 2,407
  • 4
  • 20
  • 39

6 Answers6

11

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!

Liel
  • 2,407
  • 4
  • 20
  • 39
  • I really liked this approach up until I got: "The storage account credentials must use the HTTPS protocol" when I tried to save the role configuration change. :/ – Irwin May 23 '14 at 14:32
  • the emulator file locations have changed. You can find the files in: C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator\WAStorageEmulator.exe.config and the fabric in C:\Program Files\Microsoft SDKs\Azure\Emulator\DevFC.exe.config – markwilde Dec 08 '14 at 21:11
4

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.)

Community
  • 1
  • 1
Santosh
  • 2,430
  • 5
  • 33
  • 47
4

I know this has already been answered, but there hasn't been a simple solution to this problem posted yet. Here is what I did to get my Mac talking to my Azure Storage Emulator(v4.3) running on my PC all over my LAN.

I'm running Windows 10 Version 1511 with v4.3 of the Azure Storage Emulator at time of writing.

  1. Make sure the Azure Storage Emulator is off. You can do that by opening up the Azure Storage Emulator command prompt. You can find it by typing Azure Storage Emulator into the Start menu. Once it's open, type AzureStorageEmulator stop.
  2. Grab the computer's IP address that is running the Azure Storage Emulator. Type ipconfig into the command prompt you already have open. Find the IPV4 Address - should be something like 192.168.1.xxx
  3. Open the file located at C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe.config
  4. In the StorageEmulatorConfig section, edit each service so that it looks like below. Obviously replace the "xxx.xxx.xxx.xxx" with your actual IP address... But keep the ports the same!!! enter image description here
  5. Next, head on over to your firewall settings. We'll need to allow inbound connections to your computer's IP address to these the three ports listed above in the StorageEmulatorConfig section. Under Control Panel -> System and Security -> Windows Firewall -> Advanced settings -> Inbound Rules, click New Rule... on the right side of the screen. You'll be run through a wizard to set up a new rule. I'll outline what to do below:

Rule Type: Select Custom

Program: Select Customize... then Apply to services only

Protocol and Ports: Set the Protocol type to TCP and set the Remote port to Specific Ports and in the input box enter 10000-10002. That will add the range of ports specified in the StorageEmulatorConfig section to this rule and in turn allow incoming connections through those ports.

Scope: Skip this section, have it apply to all IP addresses for simplicity sake

Action: Allow the connection

Profile: Depending on what connection profile you are running on, you should select the appropriate one. In my case, my computer was connected to the LAN in my house, so I was connected to a Private network. I deselected Domain and Public. I would recommend doing the same.

Name: Azure Storage Emulator

Hit finish and you're done!... with that part...

  1. Open an Administrator elevated command prompt and enter the following commands (Note: replace the xxx.xxx.xxx.xxx with your IP address!!!):

    netsh http add urlacl url=http://xxx.xxx.xxx.xxx:10000/ user=everyone

    netsh http add urlacl url=http://xxx.xxx.xxx.xxx:10001/ user=everyone

    netsh http add urlacl url=http://xxx.xxx.xxx.xxx:10002/ user=everyone

  2. Open a browser on the device where you are trying to connect to the Azure Storage Emulator and try to access the following URL's:

    http://xxx.xxx.xxx.xxx:10002/

    http://xxx.xxx.xxx.xxx:10002/

    http://xxx.xxx.xxx.xxx:10002/

If you get a response back that's something like this:

InvalidUriThe requested URI does not represent any resource on the server.

then you're golden... If not, post a comment and I'll update my response.

It's important to note that you must update the connection string in the .config file of the project where you are generating the urls to access your images (assuming that's what you're doing). YOU MAY NO LONGER USE THE DEVELOPMENT CONNECTION STRING SHORTCUT! It must be updated to: (replace the xxx.xxx.xxx.xxx with the IP address from above:

DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://xxx.xxx.xxx.xxx:10000/devstoreaccount1;TableEndpoint=http://xxx.xxx.xxx.xxx:10002/devstoreaccount1;QueueEndpoint=http://xxx.xxx.xxx.xxx:10001/devstoreaccount1;

If you have this in your AppSettings section and you format it nicely with \n's, you'll break the string and the Storage component won't recognize it as a valid connection string. So keep it one long annoying string.

Stephen Sweriduk
  • 278
  • 6
  • 11
2

Since you're already using (regular) IIS and you claim that it works, you can use Server Farming as some kind of a Reverse Proxy + Load Balancer to achieve your goal:

  1. Run your WebRole project and save the internal Urls (as appears in the image 127.255.0.2:82).

  2. Open IIS Manager > Server Farms > Create Server Farm.

  3. Choose a name and click Next. in the next panel ('Add Server') add all the Urls you gathered in step 1 and Finish.

  4. Click Yes when asked if you want to create the appropriate Rewrite Rules for this Farm.

  5. Under Server Farms list, click on your new Farm and choose Proxy from the icons on the right, check the Reverse rewrite host in response headers checkbox.

  6. You can now use your regular IIS binding address to access the Emulator instances (once running).

P.S: If you want to reverse this changes, delete the Farm. then click on your computer / server name (root item) in the left tree, choose Url Rewrite on the right, and delete ARR rules.

haim770
  • 48,394
  • 7
  • 105
  • 133
  • Thank you! I will check it out soon, and I will be back to this post for the results – Liel May 28 '13 at 06:51
  • I understand that those settings are available on `IIS`, and not on `IIS Express`. Is that correct? – Liel May 28 '13 at 17:59
  • Thanks for your help. Although your answer is helpful, It's not the answer I was hoping for. I have multiple development platforms, and I don't want to install the full `IIS` on all of them. – Liel May 29 '13 at 04:09
  • I don't consider it as the 'right' answer either, i think you need to concentrate on how to make IIS Express listen on non 127.* addresses. – haim770 May 29 '13 at 05:25
1

I have found a way, thanks to this great post here.

Apparently, by re-routing any traffic sent to the my local IP address (e.g. 192.168.0.1) to 127.0.0.1, I am now able to use Windows Phone 8 Emulator against Azure Cloud Emulator instances.

The way I did the routing is by using a simple app named PassPort, but I assume that there are many alternatives to it.

Liel
  • 2,407
  • 4
  • 20
  • 39
  • The other method did not work for me, but this method worked perfectly on VS 2012 on Win 8 – talkol Sep 23 '13 at 17:47
  • Glad to know. Weird the other one didn't work though. What was wrong? I use the other method all the time and it works smoothly... – Liel Sep 23 '13 at 21:58
  • I'm using VS 2012 on Windows 8, with IIS Express. Changed DevFC.exe.config, restarted the service, even booted my machine. Disabled my FW. Made sure all is running as admin. But the web role just jumped to 127.0.0.3 instead of my external IP – talkol Sep 24 '13 at 09:20
0

It's recommended to use port forwarding because of the instability of Azure Emulator. However, it doesn't work when connectaddress is 127.0.0.1 using the built-in tool netsh on my windows 7 (see for detail: problem with adding a portproxy using netsh). I search and find PassPort port forwarding utility Win XP to help me with port forwarding. enter image description here

samm
  • 620
  • 10
  • 22