Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Hosted-services / web-hosting

Host WCF on LocalHost and access via Internet

4.20/5 (7 votes)
1 Sep 2014CPOL3 min read 40.5K  
Consume WCF service/ access WCF service, that hosted on Localhost (IIS 7.5 or IIS express)

Introduction

We all facing problems to test WCF service in our local environments, generally in iPhone, Android and all other mobile device. I also came across with this issue recently. I have created WCF service for mobile app and I want to test it with app (iPhone, Android) but problem I have faced it that I doesn’t have Hosting Server to host my WCF service and I must have to do this with my Local service (Local IIS / localhost). Here is the solution for the same and we can use our localhost to test WCF service in iPhone and Android.

Background

Here I will present some good solution to our all developer to host WCF service on localhost and access via Internet and access the same on iPhone and Android. It’s pretty simple and straight forward.

Using the code

First you should create WCF Service using this article -http://mikesknowledgebase.azurewebsites.net/pages/Services/WebServices-Page1.htm and then continue follow this article. I assume that now you have WCF service created with your local machine (running successfully) and you are looking for host the same in local IIS. All right, first go to IIS and create Application under Default Web Site (Right click on Default web site and “Add Application”) – Review Step-1 snap shot.

Step -1

STEP – 1

Now give alias for your virtual directory and set path from your local drive (Review step-2 snap shot)

Step - 2

STEP – 2

Make sure your default app pool set to .NET CLR V4.0 (review step-3 snap shot). Now all done, your WCF service is not hosted on Localhost.

Step - 3

STEP – 3

You can test it using browse (review step-4 snap shot).

Step - 4

STEP - 4

Your WCF service is not running successfully on localhost (Review step – 5 snap shot).

Image 5

STEP - 5

To access the same via LAN (Local Area Network) you must disable Firewall for you Private networks (Make sure you have to just disable private network not public). Test your WCF service across the LAN and see are you able to test it on another computer? Yes hopefully you are doing well.

Now we have WCF service and it is running on localhost on your machine as well as over LAN. Now we have to test/ consume the same on iPhone/ Android/ Any mobile device app, it’s pretty simple. Follow below steps.

1.     Go to ngrok.com, download the archive and extract it to wherever you’d like ngrok to live on your computer.

2.     Open up a command line terminal and go to the folder you extracted ngrok to. Run the following command to create a tunnel to your localhost on port 80: ngrok 80

3.     You’ll see a screen like so:  813650/ngrok_cmd.jpg

4.     In the example above, we’ve got our temp URL (http://3dfab6bf.ngrok.com) being forwarded to our localhost on 127.0.0.1:80.

Ahh, all process now done!! Above url is your temporary URL to use via internet to access your LocalHost anywhere. You should use it on iPhone app (code behind to call wcf service) or run the same on browser or consume it on any other app using URL above.

NoteIt’s not permanent solution but you should test your WCF service using above scenario – using localhost. The address of ngrok will change every time when you run using command prompt.

Hope have got solution from this article. 

Points of Interest

Yes there is really a good solution I found using ngrok, because I have to test my WCF service without host it on server (Host server) and I have do that!! I have learn something new and hopefully you have also. 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)