I want to create a client and a server program using WCF. The communication between them will be TCP. The client will be a windows form where one can insert the host name and then it will list all the servers running on that machine.
Is there a way to do this? I.e. to browse all the WCF services in the machine host?
WCF Discovery - http://msdn.microsoft.com/en-us/library/dd456782.aspx
Windows Communication Foundation (WCF) provides support to enable services to be discoverable at runtime in an interoperable way using the WS-Discovery protocol. WCF services can announce their availability to the network using a multicast message or to a discovery proxy server. Client applications can search the network or a discovery proxy server to find services that meet a set of criteria.
How to: Programmatically Add Discoverability to a WCF Service and Client - http://msdn.microsoft.com/en-us/library/dd456783.aspx
There's no automatic way to do this. There have been various directory service protocols over the years but they've never really taken off. The one that has had most success overall is known as Multicast DNS or zeroconf. However the Windows APIs don't support it very well. Apple supports it under the name Bonjour and Linux supports it under the name Avahi.
The closest Windows equivalent is UPnP SSDP but after some well publicized security vulnerabilities were found, Microsoft dropped support for it by and large. There was an IPv6 rough equivalent known as PNRP (Peer Name Resolution Protocol) but this has also largely fallen out of use.
So, really your choices are to find an mDns library for Windows or to write your own.
Related
I am writing a notification client desktop application to be installed on multiple machines on a single network. These clients will communicate with a central windows service running on a single machine within the same network. Both the client and service are written in C#.Net. I am trying to determine what technologies or frameworks I should use for communication between the client apps and the windows service. I hope to use a push notification pattern instead of polling from the client.
So far I have looked into SignalR and WCF. WCF with NamedPipes looked promising, but I saw that a limitation of the WCF NamedPipes implementation is that it has to be on the same machine, so that won't work for me. SignalR seems like a good option, but I wasn't sure if there is another framework out there that won't require hosting a web server to support HTTP.
Any Suggestions?
You can consider MSMQ to send messages. https://msdn.microsoft.com/en-us/library/ms978430.aspx
This framework does not require anything special, as it is included with Windows. You may need to install the MSMQ as a Windows Feature. In my use it has been a pretty good utility that allows notifications and a host of other features.
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 need multiple clients that talk to a WCF service. The WCF service also must be able to connect to any one of the clients also.
So - it sounds like the server and the clients need to have both a WCF server and client built into each one.
Is this correct or is there some way to do this?
I was looking at NetPeerTcpBinding, but that is obsolete. To be fair I'm not sure if that is a valid solution either.
Background:
I plan to have a Windows service installed on hundreds of machines in our network with a WCF service and a WCF client built in.
I will have one Windows service installed on a server with a WCF service and a client built in.
I will have a Windows Forms application
I will have a database
The clients on the network will connect to the service running on the server in order to insert some information on the database.
The user will use the Windows Forms application to connect to the Windows service on the server and this Windows service will connect to the relevant client on the factory floor (to allow remote browsing of files and folders).
Hence I believe the machines on the floor and the server both require a WCF cleint and service built in.
The reason people are recommending wsHttpDualBinding is because it is in itself a secure and interoperable binding that is designed for use with duplex service contracts that allows both services and clients to send and receive messages.
The type of communication mentioned 'duplex' has several variations. Half and Full are the simplest.
Half Duplex: Works like a walkie-talkie, one person may speak at any given time.
Full Duplex: Like a phone, any person may speak at any given time.
Each will introduce a benefit and a problem, they also provide ways to build this communication more effectively based upon your needs.
I'm slightly confused, but I'll attempt to clarify.
You have an assortment of approaches that may occur here, a Windows Communication Foundation (WCF) Service requires the following:
Address
Binding
Contract
Those are essentially the "ABC's" for WCF. The creation of those depicts a picture like this:
As you can see the Service will contain:
Host
Service
Client
The host houses the service which the client will consume so those service methods perform a desired task. An example representation:
As you see Client-1 is going through the Internet (HTTP, HTTPS, etc.) then will hit the Host, which will have the service perform those tasks.
Now Client-n is consuming the service locally, so it is talking over (TCP, etc.) as an example.
The easiest way to remember: One service can be consumed by however many clients require those methods to perform a task. You can create very complex models using a service-oriented architecture (SOA).
All WCF is, is a mean to connect your application to a host or
centralized location you may not have access to.
As you can see in the above image, the Client communicates through a Service to the Host. Which performs a series of task. WCF will talk over an array of protocols. Hopefully this will provide a better understanding of how WCF is structured.
There are a lot of tutorials and even post to get you started. Some excellent books such as "WCF Step by Step".
Essentially your looking for an asynchronous full duplex connection, or a synchronous full duplex service. As mentioned above, your task in essence is the point of a Service.
The question: How does this work best?
It will boil down to your design. There are limitations and structures that you will need to adhere to to truly optimize it for your goal.
Such obstacles may be:
Server Load
Communication Path
Security
Multiple Clients Altering UI / Same Data
Etc.
The list continues and continues. I'd really look up tutorials or a few books on WCF. Here are a few:
WCF Step by Step
WCF Multi-Tier Development
WCF Service Development
They will help you work with the service structure to adhere to your desired goal.
Remember the "ABCs" for the most success with WCF.
Use wsDualHttpBinding if you want your service communicate with your clients.
Read WS Dual HTTP.
You might want to try out creating a WCF service using netTcpBinding. It will work for your requirements. You can use the article How to: Use netTcpBinding with Windows Authentication and Transport Security in WCF Calling from Windows Forms as a start:
Also, there are many examples included within the WCF Samples package which you can use.
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
How to call Windows Service from Windows Service in C#.NET?
Please suggest a code related to the same for calling the Windows service within Windows Service.
If by windows service you me a some code running as service under the service controller. Then any number of API's exist, from WCF, remoting, MSMQ, sockets, etc. all way to shared memory (memory mapped files). If you give us more information as to what you're trying to achieve, then we can probably be more precise.
The preferred way of communication between separate windows apps is WCF - the Windows Communication Foundation which was introduced with .NET 3.0. It supports a wide variety of communication protocols (HTTP, TCP/IP) and offer a vast number of options and possibilities.
It allows you to send messages between two programs - no matter what they are. Windows NT Services are just fine.
In order to exchange messages, you will need to define one program to be the "server" and the other to be the "client". You will also need to define a service contract - an interface that defines the communication service and its methods.
The server part then needs to implement that service, and the client needs to create a proxy for that service, and then then two sides can exchange messages.