Communication Between a WebServer and WinForm Application (Dynamic IP)
I have a requirement where I need to pass data between a webserver and a windows service/desktop app.
The idea is like this:
Method #1
1. User opens the web page (hosted on remote web server) and clicks "See what iPrank is doing now" button.
2. The web server connects to a webservice running on MY computer. (hosted inside a Winform application, using Cassinni++).
3. My webservice then sends my data back to web server.
4. Web server displays the data to the user's browser.
Both the web server and my own internal server have webservices. They can talk with one another without any problem.
But, the problem is, I have dynamic IP. So, through a separate webservice I'm supplying my IP to the webserver every few seconds.
For example currently, URL to my internal (hosted inside Winform app) webserver is http://1.2.3.4:8080 (1.2.3.4 is my external IP)
This works for my own computer/network. Other people can connect to my internal web server from any network/internet.
But, in some other computer network this doesn't work. Even if I disable firewall, I'm unable to ping to those computers using their external ip.
A quick search returned me results, most of them are talking about changing default gateway or configuring router.
This software will be used by small office users. Most of them do not know about configuring network.
So, here is my second (bad) idea.
Method #2
1. User opens the web page (hosted on remote web server) and clicks "See what iPrank is doing now" button. (Let us call it COMMAND)
2. The web server then saves the 'COMMAND' in a database table and waits. (Thread.Sleep() or Timer).
3. My desktop app (no internal webserver/webservice in this case) periodically checks the remote database server for any new pending COMMAND every second.
4. When the desktop app finds there is a new COMMAND, it executes that COMMAND and saves the result in the remote database.
5. When the web server finds that a new result has been posted for that COMMAND. It gets the data and renders the page.
As you can see, using method#2 I don't need to host any web service on client's computer. Just a little desktop app running on system tray/service is enough.
But, this method is slower and not 'proffessional'.
Can anyone suggest me any better idea ? (Not using WCF)
If it is not possible with Winforms, can anyone suggest me a 'smoother' data transfer for method#2 ?
Re: Communication Between a WebServer and WinForm Application (Dynamic IP)
This is like telling your little birdies to build a nest without stuff!
I don't fully understand why you need to literally connect the two computers involved. Surely the whole point of having a server in between is that it can act as both a receiver and transmitter. You can both send data to it and receive data from it independently of other connections that may or may not be active at the time. Also, having a Dynamic IP address doesn't mean that you have a different one every few seconds! That would be totally unworkable. At most it changes every time you log on (implicitly or explicitly).
Re: Communication Between a WebServer and WinForm Application (Dynamic IP)
Sorry for late reply.
In this situation WCF will not work (I tested it.). Or hosting my own embedded website/IIS will not work either. That is the limitation of my client's ISP.
Just to clarify, I want this communication like this:
Viewer's Browser (request) -> Remote Website (send command) -> Remote Computer (send data) -> Remote Website (prepare page) -> Viewer's Browser (show page)
And I agree with you about the Dynamic IP thing. It is better to push the remote computer's IP to the server every 5min or so.
Edit:
The following text may help to understand my current method more clearly:
Browser: Request-------------------------------------------------------------------------------------------------------------------------> show page
website: -------Save command to db ------- wait ----------- wait ------ wait ----------> Get submitted data from database -> prepare page
Remote comp: (polling)----------> Got Pending command -> Get Data -> post data to db --> poll again
Re: Communication Between a WebServer and WinForm Application (Dynamic IP)
How about using something like Dynamic DNS to keep track of your external DHCP IP address.
Here is one site for example:
http://www.no-ip.com/personal/
Re: Communication Between a WebServer and WinForm Application (Dynamic IP)
No. Dynamic DNS will not work either. (IP is not a problem.)
The problem is the ISP. They severely restricts many things.
Re: Communication Between a WebServer and WinForm Application (Dynamic IP)
Quote:
Originally Posted by
iPrank
No. Dynamic DNS will not work either. (IP is not a problem.)
The problem is the ISP. They severely restricts many things.
Ah ok! How about changing to a different ISP?
Re: Communication Between a WebServer and WinForm Application (Dynamic IP)
I suppose I am a bit confused. I'm with dun on this as far as the web host should have the needed data that the client is requesting versus the client contacting web host and web host contacting you.
Also, I don't see how WCF won't work. It is a framework for communication via multiple channels in multiple protocols. WCF can be structured to use IP channels with HTTP protocol, so I can't see how you ISP blocks it as if that where the case, how would you communicate with the interenet?!?!?
You would most likely use the wsHttpBinding if you are hosting it inside an WinForm application.
Site with types of binding available: http://wcftutorial.net/WCF-Types-of-Binding.aspx
EDIT: I did notice that the site didn't show webHttpBinding which enables a RESTful type of service while BasicHttpBinding and wsHttpBinding is a SOAP style service.
Re: Communication Between a WebServer and WinForm Application (Dynamic IP)
Somehow the ISP blocks "hosting" on local computer. (Or it could be router problem.)
But my first guess is the ISP. Because they also blocks POP and some other things.
(I can't change ISP. My client wants a solution that will work with this ISP.)
My client's idea is, "If user can view webpage from his computer, he should be able to use our software without any network/router/ISP configuration/change".
I must say, my WCF skill is limited. I tried a test program to host a http service. But it faced same problem as my winform program.
Thanks for the link. I'll try other types of binding and let you know.
Re: Communication Between a WebServer and WinForm Application (Dynamic IP)
Just to note, a WCF service can be hosted inside of any project, Console, WinForm, WPF, IIS, Windows Service, etc..
You might want to make sure you have your network configured properly. If you are using your home network on a simple SOHO router, make sure you have the port forwarding setup correctly.