I've developped a WPF composite application which is installed through MSI in c:\Program Files\WPFAPP1 on a Windows Server 2008.
Due to the targeted system environment constraint, several local windows account users launched the main .exe file (and thus start each one an instance of this WPF app) from a remote machine with a .RDP link.
Each Windows user is a known WPF application user (user access rights).
I would like to develop a .NET component to share data between users and provide a messenger-like feature : can I achieve this by using WCF service with named pipes please?
Thanks for your reply,
It is possible, but far from an ideal solution. I have used named pipes for inter-process communication, but only for time signalling where the 2 processes had to be synchronized. It was not very reliable and had its weaknesses.
Named pipes communication requires additional threads to be running all the time listening for messages and the other processes would have to know exactly which name key to use to communicate with a particular process.
Basically, you would be far better off creating a client/server architecture using WCF and have the clients send messages up to the server to be distributed to the other clients. You could use a duplex channel like NetTcp or WsHttp to push messages from server to client, or have clients poll the server for new messages.
Related
Background
I have multiple servers that I currently connect to remotely to run a number of different commands/scripts to obtain information about the servers and/or applications running on the servers.
I'd like to automate running the commands/scripts (or the code contained in the scripts converted to C#/.NET) and have the server send alerts/notifications/messages to a client (basically a Windows Form) running on multiple workstations, but need some guidance.
For reference, I have limited experience creating Windows Services, but feel fairly confident in being able to create them on the server to handle to command/script automation, which I'm assuming would be the best way to go about handling the command/script automation on the server (since the commands/scripts would need to be run all the time or at set intervals).
Question
How can I connect multiple servers to multiple clients so that the server sends alerts/notifications/messages to the client when a command/script or even an event occurs on the server?
For instance, if an application on the server has a built-in command that can be run to determine the status of the application (up, down, limbo, etc.), I would like the Windows Form on the client to receive an alert from the server when the command returns "down" or "limbo" when it is run, presumably from a Windows Service. The alerts would be displayed on the Windows Form that would be setup basically as a dashboard for the servers that the client can connect to.
An even better outcome would be that the client runs as a background application and a notification appears similar to how Microsoft Outlook displays a notification when new email messages arrive (although these notifications would likely require user interaction to close instead of fading out like the Outlook notifications).
I would also like for the client to use a configuration file that has the connection information for the servers in it so that the servers being used can be changed quickly new servers are added or existing servers are decommissioned.
Research (so far)
I've read about WCF and duplex contracts, and how WCF can be hosted in Windows Services. From what I've read, this seems promising. However, I'm not quite sure how I would set this up so that the client can connect to a WCF service on multiple servers.
One thing that I'm concerned about with WCF is that in all of the WCF examples (which implement a calculator-type service) I've seen the client has to initiate the communication with the server in order to receive a message through a callback. In the calculator service examples, the client sends numbers to the service and the result is provided in the callback. I've also seen an asynchronous example, but in that example the client initiated a single, long running request and the callback returned a single response when it was finished processing.
And, just so I'm clear about bindings in WCF, it is possible to create and use bindings for multiple servers using a configuration file without having to use SvcUtil.exe to generate the code, correct? The reason I ask is because the servers that will be configured will likely be change for different users, so the client needs to be flexible when connecting to the services.
I've just now started looking at Sockets, but I'm not familiar enough with them to know if this would be the better option to achieve my objective.
Summary
I'm just looking for guidance, so if you can help direct me to some resources that will help me achieve my objective, I would appreciate it. I've searched extensively, but the majority of my searching either doesn't apply to my scenario, it is limited to a single server/client interaction, or it is limited to a single server with multiple clients.
Since I'm not sure what direction to go in, I don't have any code examples, although I have implemented the examples in the following Microsoft article: Windows Communication Foundation - Getting Started Tutorial
So you want to build a system of
multiple servers which execute commands on the computer they are running on
multiple clients which will receive the status of the commands executed on server or such information from the server
This would be my advice
Servers can be implemented as windows service. You will be able to administrate them easily this way using the services console or the scm. Checkout this link for a creating a simple C# service How do you write and use a Windows Service in C#?
Also, you can set the service to run as an in-built service user with different levels of permissions in addition to regular user accounts.
I have not used WCF, but usually clients connect to the server; this is a pretty common model, and hence all samples are such. Initiating connection from server is not a big deal (at least in a socket program), but just a bad model. You have to ask yourself, if no client is connected to your servers, how can they relay a status to the end user. You have to think clearly about the communication model. I would suggest a central repository of messages. It can be a file on a shared file system or a database or any such entity which can act as a data repository. This way all servers can convey there messages without caring if a client is connected or not. You can use Sockets to achieve what you want to do. Check the asychronous socket server sample from MSDN to understand how to do it.
Making the client run in the background and just have a notification area icon is also easy in c#. You can use NotifyIcon Class for that. This CodeProject article (Formless System Tray Application) demonstrates its usage. To show notification a la outlook style, you can refer to the following post: How to create form popup from from system tray on windows application (not web) with c#. Look at not only the accepted answer but other answers too; there are lot of useful links in it.
So far we have windows service talking over sockets, storing messages in a central repository and capable of handling multiple clients with toast style pops for client side notification.
You need a far richer client side GUI so the end users can take actions on the messages sent from the server. You can maintain a list of servers in app.config for the client that the client connects on startup. You should to provide a GUI for users to manage all servers and their connections.
Lat but not least, by building such a client server model, you are effectively building a security loophole in your systems. You should implement a good authorization mechanism. Checkout the following post: Authenticate user in WinForms (Nothing to do with ASP.Net)
EDIT:
You can also implement your server to accept "custom command" when you implement it as a service. This way, your client server communication will be standardized by using ServiceController to pass the command. This post might help: How to send a custom command to a .NET windows Service from .NET code?.
Don't get confused in the "command" terminology here. ServiceController issues standard commands to a service for start, stop, pause, resume and restart the service. These are the same items you see on the context menu when you right click a service in the services.msc snap-in. The same way a service can respond to custom commands. In your case the custom command maybe a request to execute a process.
Note that some mechanisms I have described are geared towards an intranet setup while others scale fine on both intranet and internet
Short Verstion: I have a task that I need to make an application get a computer's camera screenshots, and send to another computer running a Windows Service, in the same local network (but not connected to the internet), along with some other information.
Long Explanation: We have an application that runs in the background while the user takes a survey, and we get the user's information such as ID and we save his answers along with other information (only pictures at the moment).
We convert these pictures to data and send them to a WebService, which then saves in a server.
Now we're implementing an "offline" version of this functionality, and we're supposed to save the user's data to a specific computer in the local area network, running another application that saves these data to later upload them to the server when it's online.
Question What do I need on both PCs for this communication to work?
Is it possible to access the Windows Service in the Host PC if it doesn't have IIS installed? (It'll be a client machine so it probably won't have it).
I've been trying to google to understand what should I search/understand but I couldn't find anything that wasn't about WCF and IIS / Online services.
you need some form of communication between the 2. It could be TCP/IP sockets or WCF or classic webservices... but if it is webservices then you DO need it hosted in IIS just like WCF. But WCF allows you to not only host it in IIS but it can be self hosting in your application or you can also use the Windows Activation Services (WAS) too. TCP/IP sockets can also be a solution here. I would lean towards TCP/IP Sockets as the problem you describe is more suited for this than a full bloated service.
We are planning on implementing our new software application as shown below.
Does this architecture look fit for purpose?
Items to Note:
There are many PC's
The pc has a WCF client as it needs to upload data to the
database periodically.
The PC has a server because the end user on the terminal server needs
to be able to interrogate the pc for information
The terminal server is the GUI for users so they can remotely connect
to a specific PC to interrogate the pc for information
We are using basicHttpBinding below
What else have we considered?
We have tried WCF NetPeerTcpBinding (i.e P2P) but it does not support
request-reply operations.
We have tried WCF Duplex but with the requirements listed above in the items to note section we would end up with a client and server at both ends anyway.
Well I apologize but I basically disagree with your architecture.
WCF is not designed or suited for anything other than a request-response communication.
Its full duplex ability will not enable your server side to issue communication to a specific client unless that client already issued a connection to the server.
That means that in order to achieve a prestigious online full duplex communication with all your clients - all your clients must maintain an open port to the server.
Having a dual client and server per PC in order to achieve an online full duplex is a step forward as it will solve the issue of keeping a port open per client however it has downsides in terms of security as it means that the specific PC is open to receive multiple connection requests. Another issue can occur with deadly reentrancies if you not careful. So, basically you will be saving 'ports' in exchange for architecture
maintainability and fitness to your solution.
So if you are targeting a deployment of around 200-300 PC's your architecture will hold but if you are targeting a larger deployment of thousands of PC's - it will not hold.
I am new to WCF (Just a day or 2). I am planning to make an application having Client/Server
WCF Service (On Server hosted as windows service):
Will invoke some commands using (Process.Start())
Will send some information from my database
Questions:
What WCF binding should I use? WsDualhttp or netTCP (Please elaborate if you can)
Does WCF works with SqlServer + EF 4.1
Server UI:
This will primarily will be used to
Start ot stop the above service
Change Address (localhost to [My Ip address]) and Port
Show status of service (Running or dead)
Questions:
How can I Change the address and port of my WCF service from this UI (it will be a different project and hence different config file).
Client App:
Used to issue commands to WCF service.
Get to know if the service is running or dead.
Receive status messages for task completion or faults.
Also, can the windows installer be combined to install ServerUI + WCF Service + Windows service?
WCF Service
Here are a couple links on choosing the right binding. Based on the scenario you're describing, I'd go with the netTCP.
C# - WCF - inter-process communication
Choosing the right WCF binding
WCF and SQL Server are independent of each other, so I wouldn't expect any problems using the Windows service to interact with your database.
I'd suggest reading up on how to start a process from a Windows service.
Server UI
I would suggest hosting another WCF service in your Windows service for interacting with your Server UI. You can use the netNamedPipeBinding since this communication channel will always be local, i.e., on the same box. So your Windows service will host two WCF services - one for the external communication with the client and one for the local communication with the configuration UI.
Installer
Yes, the Windows installer can be used, but that might be overkill for what you're describing. Of the Server UI, WCF Service, and Windows service, the only one that absolutely requires installation is the Windows service. The others could theoretically run simply by copying the assemblies to the target system. You might consider having the Windows service install itself via command line. That way you could get away with a self-extracting executable using software like WinZip. This might be less heavyweight than a formal install. If you go this route, have a look at the step-by-step here.
Ha a look at WCF duplex services:
http://msdn.microsoft.com/en-us/library/ms731064.aspx
Why do you want to have a interface to an windows service? And if you have access to IIS7 and WAS, I would recommend to use it instead of self-hosting in windows service.
Here is a good starting point for WCF Configuration Management:
http://msdn.microsoft.com/en-us/library/ff650534.aspx
Yes, you can use windows installer.
Cheers
--Jocke
The requirement:
My [windows/web] service in C# 3.5 periodically has something to say about its state. It could be a progress status, log entry, error or warning, or signal of data availability.
Client applications are on the same network, and they would like to learn about some of these messages.
Clients start and stop randomly, largely outside of my control.
Clients are written in C#, C++ and even Delphi.
Database connection that can support storing my service's messages may not be available.
I would like my service to publish its messages (text-based protocol) for subscribers to be able to see and react to. I don't want to bother with how many clients are connected, or are there clients at all.
I was looking into named pipes, regular TCP/IP, semaphores, but I cannot seem to find anything that fits the bill.
Currently I'm forced to store a file on the network that is being currently updated, but it's not clean, and requires clients to have access to a network share.
Looks like you need to use WCF for this.
WCF can handle named pipes, TCP/IP and it can do windows and Web services.
You can have a look here:
http://msdn.microsoft.com/en-us/library/ms731082.aspx
Hope this helps!
Check out the OWIN project and the Kayak implementation.
It will allow you to run your own in-process web server.