Connecting WCF Local Host With Windows Phone Emulator

Getting Started

The Windows Phone emulator doesn't connect to a Local Host easily. I have described the procedure for Creating WCF Service and Calling it in WP Application here. But when you run the project it gives an exception.
exception

To resolve this issue some configurations must be done.

Create a firewall exception for HTTP requests to IIS Express:

  1. From the Windows Start Screen, search for Windows Firewall. Click to run the program.

  2. On the Windows Firewall screen, click Advanced settings.

  3. On the Windows Firewall with Advanced Security screen, select Inbound Rules. Then click New Rule.

  4. On the Rule Type page of the New Inbound Rule Wizard, select Port. Then click Next.

  5. On the Protocols and Ports page, enter the port number that IIS Express is using in the Specific local ports field. Then click Next.

  6. You can find the port number on the Web page of the project properties in Visual Studio.
    localhost
  7. On the Action page, select Allow the connection. Then click Next.

  8. On the Profile page, select Private and if applicable, Domain. Do not select Public. Then click Next.

  9. On the Name page, type a name for the rule, for example, Local web service for testing. Then click Finish.

Turn on HTTP Activation Feature

  1. In the Windows Features dialog box, expand .NET Framework 4.5 Advanced Services, then expand WCF Services.

  2. Under WCF Services, check the box next to HTTP Activation. Click OK to install this feature.

    HTTP Activation

Create a firewall exception for HTTP requests to IIS

    In the Allowed apps and features list, check the box next to World Wide Web Services (HTTP) to create a firewall exception for calls to the web service. Click OK.

  1. From the Windows Start Screen, search for Allow an app through Windows Firewall. Click to run the program.

  2. In the Allowed apps dialog box, click Change settings.

  3. In the Allowed apps and features list, check the box next to World Wide Web Services (HTTP) to create a firewall exception for calls to the web service. Click OK.
    Wide Web Services

Configure the service and IIS Express to accept connections from the network

  1. On the development computer, open a Command Prompt window and run ipconfig to get your IP address.

  2. From the output of ipconfig, note your IP address from the line of output captioned IPv4 Address.

  3. Now open the Command Prompt in Administrative mode and register your IP for the connection.

    Netsh http add urlacl url = http:// your ip : port / user = everyone

  4. This will result in “Reservation successfully added”.

    Note: PORT is the same port that was used to create the firewall exception.

Some Configurations in "Applicationhost.config" File

  1. Find the IIS Express configuration file, applicationhost.config from the start search bar and open it in Notepad.

  2. Now find your WCF project's name and copy the <bindings> tag and paste it below the existing <bindings> tag.

  3. In the new bindings tag, replace localhost with the computer's IP address.
    1. <bindings>  
    2.    <binding protocol="http" bindingInformation="*:60661:localhost" />  
    3.    <binding protocol="http" bindingInformation="*:60661:<ip address>" />  
    4. </bindings>  
  4. Save the changed file.

Configure the service and IIS to accept connections from the network:

  1. Start or restart Visual Studio with the Run as administrator option and reopen the solution.

  2. In the WCF service project, right-click on the project and select Properties.

  3. In Project Designer, click Web to open the page of web settings.

  4. Deselect the Use IIS Express option. The URL displayed in the Project URL text box changes.

  5. In the URL text box, replace LocalHost with the IP address of the development computer.
    Web Services testing
  6. Click the Create Virtual Directory button. After a few seconds, a message indicates that the virtual directory has been created.

  7. Save the changes made in Project Designer.

    OR

  8. Simply replace the local host with an IP address. Don't change the port number area in the URL.

  9. Now save the changes made to the project and close Visual Studio.

  10. Reopen Visual Studio in Administrative mode, open the project and browse to the service to restart IIS Express.

  11. Right-click on the IIS Express icon in the system tray and select Show All Applications. The IIS Express dialog box opens and shows the 2 bindings for the web service in the solution.
    All Applications

  12. To verify that the service reference in the phone app project is using the IP address for the web service, check the endpoint element in the ServiceReferences.ClientConfig file.

  13. Now remove the previously added service in the phone app project and add a new service to the project with some configurations done.

Now you are done! Press F5 and enjoy the services.

Happy Coding :)

References: MSDN Blog.


Similar Articles