- 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
- Summary
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:
<
site
name
="WPUnleashed.Web"id
="22"> <application
path
="/"applicationPool
="Clr4IntegratedAppPool"> <virtualDirectory
path
="/"physicalPath
="C:\Development\Source\WP8Unleashed\Source\MainExamples\Web" /> </application
> <bindings
> <binding
protocol
="http"bindingInformation
="*:27571:localhost" /> <!--Add the following:
--> <binding
protocol
="http"bindingInformation
="*:27571:YourMachineName" /> </bindings
> </site
> - 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
Path |
Port |
C:\[Path to Samples]\WP8Unleashed\Source\MainExamples\Web\ |
27571 |
C:\[Path to Samples]\WP8Unleashed\Source\Wallet\WalletWcfServices\ |
14122 |
C:\[Path to Samples]\WP8Unleashed\Source\BackgroundAgents\Web\ |
60182 |