How to control application via webservice - c#

I want to control application (in my case it is corelDraw) ,I know I should use it's application object and I do this, but the issue now is I want to do this in webservice,
so as far as I understand if I put this code which control the application in the web-service ,my code will try to control the corel application which is on the server not on the client :(
so any hint/advice how could I do this, and control the application on the client not server ?!!!

As you already noticed web service runs on server and only result is passed to client.
Well you have a few options to control client machine over web service... Here is one of possible scenarios.
1. create web service that will provide commands for client
2. create windows service (client) that will consume your web service commands
3. inside windows service then just execute those commands in appropriate manner
Well I have to say this is not the prefered way I would take to automate corelDraw, but if you insist on using webservice as command provider it will do the job.

You need to ask yourself what is the difference between client and a server. Can a client be a server? Can a server be a client?
You make your client with CorelDraw installed to accept web-service request, i.e. effectively make it a web-service server, and then carry on as normal.
Although I would say web-service is not the best way to control such complex application as CorelDraw. I'd look in some other ways of communication between peers, like lower level network communication that would not have overhead of HTTP.

Related

C# Client-Server application

I need to write a client-server application. First of all, I'm going to write an application server. Also my app server should connect to database(MS Sql Server) and give data from it to client app. So, as I know, I should use WCF. Is it a good idea? Maybe I need to take a look for something else?
Lets start with client-server architecture.
Assuming you have finalized that you need client and server, but have you decided carefully the architecture? I mean what type of server and what type of client you are going to create?
Let's see the options here:
Server
1. What type of hosting you are going to use?
2. What type and how much load your server needs to handle?
Client
1. Type of consumer of your service
2. Do client need to be deployed on local machine or it should be web based?
There are obviously more concerns than above. Initial design should be as flexible as possible.
So, now lets look at some solutions regarding architecture.
Server:
1. Application Hosted WCF server: Each time you need to manage the server lifecycle. Also, this is not scalable. So if you are looking for scalable architecture, you need to look more.
2. IIS hosted WCF server: This might be a good idea along with some architecture concerns as per your need.
3. Web Method: Obviously this came after WCF, but WCF is still in its place. So the main difference is at What is the difference between an asp.net web method and a wcf service?
Now Client:
1. ASP.NET: This will enable to use a single client app for every platform obviously because of HTML
2. WPF/WinForms: This is going to bit tricky to use as client as you need to deploy the client app on user machine and here comes the data security problem. In former you can directly use SSL or some other way to send data to browser. While in this if you are not using WCF with HTTPS and there are some proprietary data going over wires, it may be concerns.
If you are looking for cross platform usage of your server you can use HTML.
Conclusion:
You can use Server as WCF hosted service (either in IIS or in self contained application) and client as ASP.NET.
-----------------------------If it is not big enough requirement then you can use ASP.NET as server and then browser as client (No need to create client).----------------------------
You can create server either as WCF as web methods and deploy the client on user machine.
----------------------------
WCF is nice enough and it can handle your proprietary data types as well.
WCF is a nice thing, but i would use ASP.Net Self-Hosted Web-API. It's more modern. And you have a full rest interface, which is much more popular.
Here is a comparison: WCF and ASP.NET Web API
Here is a good starting point: Self-Host ASP.NET Web API 1 (C#)

Are WCF + Callbacks suitable for sending commands to the client?

I'm trying to create a WCF service for our existing product.
The service should provide normal "webservice" features (one-way), but also act independently.
Sample scenario:
The client connects to the server
The server saves the client in a collection
Now I use an admin client / database entry to tell the client to do sth. (For example change config for log4net/NHibernate)
I've read some things about callbacks (mostly a chat system), but I'm still not sure if this will work.
Now my question is, will WCF be suitable for such a scenario or should I use TCPClient/TCPListener?

C# Traditional Server with WCF Web Service

I am creating a client application that downloads and displays market data from Yahoo! for a university project, but that also sends out notifications to mobiles (so far using Google cloud messaging). So far it's a WPF client and the "server" is a class library - so far working. What I was wondering, is can you mix this server with a WCF service - the WCF service I was planning on using for registering devices, as well as accepting and parsing commands.
So I would call .Start() on my server object, and it will be constantly running in the background, while a WCF REST service runs alongside it - or would I be better simply having a thread running on the server that can accept input... sorry if this is confusing, but just wondering if it can, or has been done before or any advice. :)
Just to explain a bit better
The client front end and the "server" are running on the same machine - I was calling it a server because it is not only updating the front end, but sending out GCM notifications at the same time. I was wondering if maybe a WCF service could be added to make it simpler to handle adding devices to a database ("server" reads a list of device reg ids from a database, sends notifications to these) by allowing an android app to details via REST or something similiar
I would explore wrapping the class library in a Windows Service (which is essentially a process that runs continuously, and can be stopped/started/paused) and keep your WCF service as a web service for client communication.
How the WCF client service communicates with the Windows service is up to you - whether you store the data in a shared database, keep it in memory and have another WCF layer communicating between the two, etc. A shared database would be the most straightforward, especially if you want to persist the data for use by other apps/services as well.
WCF Service would be useful if you had one notification service on your server with multiple WPF client application connecting to it. If you have just one application running on the same server then not sure if it will be worth the overhead.
The usual pattern is to host WCF service in IIS, that way it always starts whenever first request is received. WCF is very flexible though, therefore you can host in in Windows Service, Console Application, etc.

How to access client application from web application with service application

I would like to write a Web Application that can interact with 3D Cad program for our company. So I was thinking that I would create a program that would be locally installed on the client machines which would send and receive data back and forth from Client App to Web App. I would like to use xml for moving the data back and forth too. Does anyone suggestions or can this even be done?
In this case you need 2 way communication between app and service. and for solving that there are two way:
use two service and they must be client of each other (Hard way)
use Duplex Services. (you can use WCF-Duplex services - it's not simple)
in this case you must handle too many issue's.(take look at this)
As example:
app need to notify self on your service and service save address of active client's. so every time service want's to call one of client, service must find client's address in active-client's and then call that.
Let me know if this help you.

Execute Client Function from Server

After looking into WCF, I don't believe it can do what I need it to. What would be the appropriate way (if I have a server and client application, both C# .NET Console apps) to basically instruct the client to execute functions?
For example, if the client application has functions such as DownloadFTPFile(), CreateWindowsService(), IsServiceRunning(), etc. what would be the standard approach to telling them to execute this from the client?
I was initially just going to have the client interpret messages sent from the server, such as "downloadfile ftp://filename.zip" but I am wondering if there is a better way.
Client has Agent.
Agent connects to server, polls for cmomands
Agend executes comands.
THe server sending is tricky unless you control the environment. NAT for example makes "client sends" a nightmare. You also then open up the client for additional attacks with client polling the clietn firewall does not have tp open external access to the agent.
It is possible.
Use the callback functions along with duplexes in the WCF. You will be limited to the intranet usage or azure though, since only NetTcpBinding and NetTcpRelayBinding support it (WsHttpBinding is deprecated).
With WCF, any client can self-host a WCF service. This can make the client be a service. Add a little extra protocol between the client and the service, and you've got your wish.

Categories