We have a Website (hosted somewhere) and C# Application (which is installed on my PC). I need to accomplish the following:
Customers fill up the form on the website, i.e. the task is "created"
C# Application immediately receives this data from the website and process it
The result is sent back to the server, i.e. "task accomplished" message
The website updates status regarding this task
How do you build this kind of link between the website and an app?
In the past I've used TCPListener to communicate between two C# apps. I'm also familiar with the UDPlistener and such.. Will this knowledge be of some use? The website is going to be build on the PHP.
Some tips and advises are appreciated. Thanks.
Your website should not be dependant on an application running on your home or office PC, so the site should publish some kind of service or feed. You can make this a webservice, which is quite easy in PHP.
You then consume this service from your C# application. Make it request the new tasks regularly, by polling the service. When you've received new tasks you process them in your application, and when you've done what you want to do you update the tasks on your server using another webservice call.
All this can be done using some sort of queue in the database that backs your website.
Make the C# application a web service may be a windows host depending on your requirement
you can the webservice from php as shown here Using PHP to call a WCF web service with multiple bindings
If you have the control over your web host and your client, you could try setting up a WCF service with duplex contracts which allows the server to callback your client. Your PHP site can call the WCF service and it can in turn notify the client. Else you will have to go with the polling method where the Desktop client has to poll the web service to get the list of pending tasks.
Related
I have an application in WPF c# which will run on client machine. Another application (maybe some kind of service) on a particular server will be running all the time and will wait for any incoming message from the client app. As soon as the server receives a request from any of the client application, it triggers a command line process and also responds to the client about the staring info(whether it was successful or not) and as well as when the command line process is finished it again responds to the calling client application that it got finished.
I am new to in this area.
So my question is should I use normal windows service or Web service or WCF?(Some kind of link to a demo project will really help). Any other suggestion are also welcomed.
You did not mention if your clients will be outside of your firewall or with in the same intranet. We have intranet scenario, and we use WCF service that communicates with WPF based applications over the internal network. WCF provides Duplex feature which enables two-way client server communication using an easy to implement programming model. I recently wrote an article on this and it can give you a head start for the WCF way.
However, WCF does not have the best support for callbacks over the internet and you may have to look in to effectively using it in your case. But if it is intranet, then my suggestion is surely to go for the WCF way. Hope it helps.
I am working on a windows service that acts as a medium between a web application and a standalone client side program. In a nutshell: Before submitting a form on my web application, I want it to be encrypted by my client side standalone program. The medium of communication has to be the windows service.
My question is: How do I call a C# function in my service through JS? (This function will help me relay data back and forth between the website and the standalone application)
I was successfully using an applet to act as the medium before but I have shunned that idea as many security issues are being plotted off late.
You can self host a REST based service in a Windows Service. For example using the NancyFx framework http://nancyfx.org/. You can then make an ajax call using localhost as the endpoint, this would mean that the service MUST be installed and running on any clients which access it.
Also just a query, why are you doing your own encryption client side? You can encrypt the communications to the server using SSL and then do whatever encryption you require server side. Is this some design that is being imposed on you?
Does it have to be a Windows service?
You could write a WCF service that you host inside a Windows service. There's an article on MSDN about how to do that (http://msdn.microsoft.com/en-us/library/ms733069(v=vs.110).aspx) and there are many more on the Web.
You cannot call a function defined in a Windows service directly, you have to expose it to the outside world using some kind of endpoint, like the way WCF does.
I have a Windows service written in C# that handles processing of digital documents, and a web application written in PHP. I need to be able to notify the C# service that new documents are ready for processing.
Currently, the C# service is reading the MySQL database every 10 seconds to see if there are new tasks to be performed. This creates a 10 second lag in the responsiveness of the web application. I'd like to be able to trigger the C# service immediately when the document is ready.
I'm looking for an answer that will allow PHP to notify the C# service without any delay.
Here are some possible ideas that I've had;
Use a shared memory object between PHP and C#, and have a thread in C# wait for that object to be signaled. Is this possible with PHP?
PHP connects to C# using a socket on localhost, sends a nak and disconnects. This seems inefficient to me.
Configure MySQL to use an in-memory table, and have the C# service query the table every second.
Is it difficult to create some kind of web service in C# that uses XML or SOAP, and would there be any lag (+1 second) in calling that service via PHP?
That's all I can think of. Maybe there is some kind of standard way this should be done, and I'm just not aware of it.
It'd be pretty trivial to make a REST facade in WCF that triggers your c# service on a POST against /. Security can be layered on depending on the nature of your deployment.
http://msdn.microsoft.com/en-us/library/bb412178.aspx
I'm going to go ahead and try to answer this.
In your service, add an OnCustomCommand handler as described in this question to trigger the service work: How to send a custom command to a .NET windows Service from .NET code?
Create a separate C# application that simply sends the command to your service and call that from PHP via the exec() function.
You could self-host an ASP.NET WebAPI in your service
I'm trying to give functionality to the user where they can remotely control the client on their system from a mobile device or laptop.
What I have created is a WCF Console application which holds the contracts etc. and starts the server.
Now here's the thing, if I create a HTML page I can't do anything with it to make it communicate with the server and then the client as I'll need the HTML page to make call a method on my WPF client to initiate an action.
Has anyone had any experience with this, I think almost there with my solution it's just this wall that I've hit.
Thanks
If your looking for a way to call WCF server functions from a webpage then use Ajax enabled WCF service. Read here: http://www.codeproject.com/Articles/33234/A-beginner-s-guide-for-consuming-a-WCF-service-in
I am currently developing a C# Windows Form Application that I intend to let it interact with a server. The server will receive posting from a mobile application that I have developed and whenever a posting is received, my Windows Form Application should be notified and give me a notification. In order to do this, I intend to use WCF duplex service for it.
E.g. My mobile application sends an posting over to my server. Once my server reads and receives the new posting, the service should send a message over to my winform app to alert me that a posting is received. And the UI of the winform app should update accordingly to what I want to updated. (e.g. adding new panels)
This is basically how I wish for it to work
They way this would work is
WCF Service in running on my server
Windows Form connects to my server's WCF service using Duplex Contract
Mobile app posts to a webpage
Once the webpage receives the posting, the asp.net will invoke the WCF service
WCF duplex service receives the posting and sends the information to the winform app
My winform Application aka WCF Client updates UI with this new message received
My question is, how does step 4 proceed to step 5? To be specific, how does the service sends the information over to the winform app upon receiving the posting.
To be even more specific, once the posting is received from the webpage, the service contract is invoked and the information is sent and received by the service, how does the service make use of the call back channel to send the information over to the winform app and update the UI accordingly?
The answer to this question depends on how your WCF service is hosted and how "big" the service will eventually be (in terms of number of simultaneous clients).
The simplest scenario is a self-hosted WCF service (meaning hosted in a Windows Service or as a desktop application--not in IIS). In this case, you can use InstancePerSession mode and make your service use sessions. In this case, you'll have a 1:1 correspondence between clients and instances of your service class. When a client connects, retrieve the callback reference and store it in a static list outside of the service class. When you need to send a message to one or more clients, simply iterate over (or find the desired client in) your list and call the appropriate function on the callback contract
If you need to host your service in IIS, then the situation is trickier because you have the possibility of multiple processes hosting your service, so your list can potentially get fragmented (or blown away in the event of an app pool recycle). In this case, you'll have to use something external to your service (MSMQ, perhaps) to notify other application pool processes that a message needs to be sent.
In terms of a duplex connection, you are really just able to communicate two way over that one connection, not with all connections of the service without doing some tricky thread stuff and shutting the door on any scalability (or using something outside the service to handle to pub/sub).
One solution though that may work a lot more along the lines of what you want to do would be SignalR. It allows a single client to make a request and then you can broadcast data from that request to other clients (or target it). Take a look at its info, its sole purpose is real time communication in .NET with multiple clients.
Also another note, is that you will want to use some sort of BackgroundWorker or something for your listening thread in WinForms so that the UI is not locked while the background operations are running.