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:
- From the Windows Start Screen, search for Windows Firewall. Click to run the program.
- On the Windows Firewall screen, click Advanced settings.
- On the Windows Firewall with Advanced Security screen, select Inbound Rules. Then click New Rule.
- On the Rule Type page of the New Inbound Rule Wizard, select Port. Then click Next.
- On the Protocols and Ports page, enter the port number that IIS Express is using in the Specific local ports field. Then click Next.
- You can find the port number on the Web page of the project properties in Visual Studio.
![localhost]()
- On the Action page, select Allow the connection. Then click Next.
- On the Profile page, select Private and if applicable, Domain. Do not select Public. Then click Next.
- 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
- In the Windows Features dialog box, expand .NET Framework 4.5 Advanced Services, then expand WCF Services.
- 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.
- From the Windows Start Screen, search for Allow an app through Windows Firewall. Click to run the program.
- In the Allowed apps dialog box, click Change settings.
- 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
- On the development computer, open a Command Prompt window and run ipconfig to get your IP address.
- From the output of ipconfig, note your IP address from the line of output captioned IPv4 Address.
- 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
- 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
- Find the IIS Express configuration file, applicationhost.config from the start search bar and open it in Notepad.
- Now find your WCF project's name and copy the <bindings> tag and paste it below the existing <bindings> tag.
- In the new bindings tag, replace localhost with the computer's IP address.
- <bindings>
- <binding protocol="http" bindingInformation="*:60661:localhost" />
- <binding protocol="http" bindingInformation="*:60661:<ip address>" />
- </bindings>
- Save the changed file.
Configure the service and IIS to accept connections from the network:
- Start or restart Visual Studio with the Run as administrator option and reopen the solution.
- In the WCF service project, right-click on the project and select Properties.
- In Project Designer, click Web to open the page of web settings.
- Deselect the Use IIS Express option. The URL displayed in the Project URL text box changes.
- In the URL text box, replace LocalHost with the IP address of the development computer.
![Web Services testing]()
- Click the Create Virtual Directory button. After a few seconds, a message indicates that the virtual directory has been created.
- Save the changes made in Project Designer.
OR
- Simply replace the local host with an IP address. Don't change the port number area in the URL.
- Now save the changes made to the project and close Visual Studio.
- Reopen Visual Studio in Administrative mode, open the project and browse to the service to restart IIS Express.
- 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]()
- 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.
- 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.