The Windows Phone 8 Emulator differs from previous Windows Phone emulators in that it is a full fledged virtual machine running on Hyper-V. This creates difficulty when attempting to test local web services utilizing ASP.NET Web API. The Windows Phone client cannot simply reference localhost like it did in the past. Instead, you must make the service available to the emulator as an independent device. There are a few hoops to jump through to make this happen and here's how I achieved success.
Reorder network adapters on the Emulator
- Remove all network adapters from the Emulator in Hyper-V Manager
- Add network adapters back on the Emulator beginning with the Wireless adapter, then Wired Ethernet, then Internal Windows Phone
- At this point I was able to access internet resources like google.com and kevinkallberg.com from within the emulator.
Tell IIS Express to allow traffic to connect on an IP address in addition to localhost
- Stop the Web API site.
- Right-click and Exit IIS Express in the system tray.
- Open the folder %USERPROFILE%\Documents\IISExpress\config\
- Edit the file called applicationhost.config
- Locate the Site XML node under <configuration><system.applicationHost><sites> that matches your site.
- Copy the binding node similar to this one: <binding protocol="http" bindingInformation="*:<port>:localhost" />
- Paste the binding node directly underneath the existing one and replace localhost with your current IP address.
- Add additional bindings if you wish for each of the host machine's network adapters.
- Restart the Web API site and ensure that you can browse to it on the host machine via localhost:<port> and <ipaddress>:<port>
Add an exception in the Windows firewall
- Create an inbound rule allowing traffic on the port that IIS Express is hosting the Web API service.
- Allow this exception on Private and Domain network profiles, but not Public.
At this point, you should now be able to access the Web API site from IE Mobile on the Windows Phone Emulator by navigating to http://<ipaddress>:<port>.
Remember you can use the Pause/Break key to toggle keyboard functionality inside the Emulator.