- Understanding the Role of XAP Files
- The Windows Phone Capabilities Model
- The Threading Model for XAML-Based Graphics and Animation in Windows Phone
- Understanding the Frame Rate Counter
- The Windows Phone Application Analysis Tool
- Reading Device Information
- Applying the Model-View-ViewModel Pattern to a Windows Phone App
- Property Change Notification
- Using Commands
- Argument Validation
- A Platform-Agnostic Dialog Service
- Consuming Local Web Applications
Consuming Local Web Applications
Changes to the Windows Phone Emulator have made developing apps that communicate with web applications on the local machine more difficult to set up. Prior to Windows Phone 8, apps could rely on the emulator resolving localhost to the underlying host operating system IP address. This allowed you to rapidly set up a WCF project that could be readily consumed by your Windows Phone app.
In Windows Phone 8, the emulator is unable to resolve WCF services on the host machine without adding a URL reservation and adding a port exception to the Windows firewall.
Perform the following steps to allow a Windows Phone app to consume a service on the host machine:
- Assuming that you are working with IIS Express for local development, use the Windows File Explorer to navigate to the IIS Express config files in C:\Users\[Username]\My Documents\IISExpress\config
- Open the applicationhost.config file. Update the physicalPath attribute to the path of the project on your computer. Add an http binding for your machine’s name, as shown:
physicalPath="C:\Development\Source\WP8Unleashed\Source\MainExamples\Web" /> </
bindingInformation="*:27571:localhost" /> <!--
Add the following:--> <
bindingInformation="*:27571:YourMachineName" /> </
- To locate your machine name, from a command prompt type “HOSTNAME”. Although not necessary, you can update your hosts file and use a different name if you want, which will allow your app to be debugged on other machines more easily.
- Make a URL reservation by typing the following from an administrative command prompt:
netsh http add urlacl url=http://YourMachineName:27571/ user=everyone
- This informs HTTP.SYS that it is okay to allow access to the URL.
- To remove the reservation at a later stage, use the following:
netsh http delete urlacl url=http://YourMachineName:27571/
- Allow IIS Express through the Windows Firewall. You can do this from the command line by typing:
netsh firewall add portopening TCP 27571 IISExpressWeb enable ALL
These steps must be completed for the main WPUnleashed.Web project in the downloadable sample code, and also for the Background Agents and Wallet samples seen later in the book.
To save time, Table 2.4 lists the path and port information for the projects in the downloadable sample code.
TABLE 2.4. Path and Ports for Sample Projects
C:\[Path to Samples]\WP8Unleashed\Source\MainExamples\Web\
C:\[Path to Samples]\WP8Unleashed\Source\Wallet\WalletWcfServices\
C:\[Path to Samples]\WP8Unleashed\Source\BackgroundAgents\Web\