Click here to Skip to main content
15,881,882 members
Articles / Hosted Services / Web Hosting
Tip/Trick

Host WCF on LocalHost and access via Internet

Rate me:
Please Sign up or sign in to vote.
4.20/5 (7 votes)
1 Sep 2014CPOL3 min read 39.2K   10   10
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)


Written By
Software Developer (Senior)
India India
I am software engineer and working with .net technology since year of 2007 and I am still learning new technologies and growing my technical knowledge.

Comments and Discussions

 
QuestionWorked like a charm Pin
ZeroCode75-Jan-17 20:58
professionalZeroCode75-Jan-17 20:58 
AnswerRe: Worked like a charm Pin
Jitendra sondarva1-Feb-17 22:56
Jitendra sondarva1-Feb-17 22:56 
Questionhow to use ngrok’s -httpauth flag Pin
Tridip Bhattacharjee2-Sep-14 21:24
professionalTridip Bhattacharjee2-Sep-14 21:24 
AnswerRe: how to use ngrok’s -httpauth flag Pin
Jitendra sondarva3-Sep-14 3:11
Jitendra sondarva3-Sep-14 3:11 
GeneralMy vote of 1 Pin
Lucas Ontivero2-Sep-14 5:08
professionalLucas Ontivero2-Sep-14 5:08 
GeneralRe: My vote of 1 Pin
Jitendra sondarva2-Sep-14 23:00
Jitendra sondarva2-Sep-14 23:00 
Questionpretty useless without the pictures Pin
BigTimber@home2-Sep-14 1:41
professionalBigTimber@home2-Sep-14 1:41 
AnswerRe: pretty useless without the pictures Pin
Jitendra sondarva2-Sep-14 2:24
Jitendra sondarva2-Sep-14 2:24 
Questionpictures are not showing Pin
Tridip Bhattacharjee2-Sep-14 0:50
professionalTridip Bhattacharjee2-Sep-14 0:50 
AnswerRe: pictures are not showing Pin
Jitendra sondarva2-Sep-14 1:11
Jitendra sondarva2-Sep-14 1:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.