,

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:

1. 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 DocumentsIISExpressconfig

2. 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:DevelopmentSourceWP8UnleashedSourceMainExamplesWeb" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:27571:localhost" />
        <!-- Add the following: -->
        <binding protocol="http" bindingInformation="*:27571:YourMachineName" />
    </bindings>
</site>

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

4. 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/

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


Note

If you do not perform the steps to enable communication with WCF service on the local machine, several of the sample apps presented in this book that make use of local WCF services will not work.


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

Image

Tip

To locate the port that a Web project is using, open its properties page and select the Web tab.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.9.12