Click here to Skip to main content
Click here to Skip to main content

Host WCF on LocalHost and access via Internet

, 1 Sep 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
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).

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)

Share

About the Author

Jitendra sondarva
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

 
Questionhow to use ngrok’s -httpauth flag PinmemberTridip Bhattacharjee2-Sep-14 22:24 
AnswerRe: how to use ngrok’s -httpauth flag PinmemberJitendra sondarva3-Sep-14 4:11 
GeneralMy vote of 1 Pinmemberlucasontivero2-Sep-14 6:08 
GeneralRe: My vote of 1 PinmemberJitendra sondarva3-Sep-14 0:00 
Questionpretty useless without the pictures PinmemberBigTimber@home2-Sep-14 2:41 
AnswerRe: pretty useless without the pictures PinmemberJitendra sondarva2-Sep-14 3:24 
Questionpictures are not showing PinmemberTridip Bhattacharjee2-Sep-14 1:50 
AnswerRe: pictures are not showing PinmemberJitendra sondarva2-Sep-14 2:11 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150414.1 | Last Updated 1 Sep 2014
Article Copyright 2014 by Jitendra sondarva
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid