What is the main difference between Request-Response and Duplex in WCF Message Exchange Pattern?
The main difference is that, after the client establishes a channel to the service, the service can call the client independently at any time. In Request-Response the service only communicates back after receiving a Request from the client. So by using duplex you receive an event-like behavior from the client perspective. Obviously such enhancement requires a Session to be maintained (instance mode PerSession on the service). You can read more on the msdn.
Related
I have system like this:
Windows service (WCF, data/events) <-> Web app <-> Web client
I need simultaneous response for clients requests. I have some events from service for clients too. So duplex channel is the way to go. But I need high throughput, because clients calls simultaneously.
Request/reply approach
In order not to serialize channel requests I need more channels for parallel calls, right? But how to handle callback channel then? Ho to keep it still open for receiving events, even on channel errors?
OneWay approach
On channel should be enough (no waiting for data preparation), but how to link data sent to callback with original request, to be able to compose response for client?
What is the way to go? Thank you.
In a simple case, when a web client sends a request to the web app, and web app (possibly) sends a request(s) to WCF service, there's no need in duplex binding at all.
As for events, raised by the service to be fired in Web client, I'd suggest to use a message broker which supports WebSockets - for example RabbitMQ. It has a plugin compatible with WebSockets and WCF binding.
Putting things together, one can create a RabbitMQ server, which accepts messages from WCF service and sends it to Web client, which subscribes to the event feed from Javascript.
I'm thinking of what should be practical example of using WCF one way message exchange,
since I'm concerned about success or failure of any operation which I send to WCF service
and in one way message exchange - WCF service does not report success or failure of operation.
When your binding is MSMQ, you must use one-way operations.
All service operations must be one-way because the default queued binding in WCF does not support duplex communication using queues - Queuing in WCF
Plus, callbacks to a possible client regardless of protocol should be one-way in case the client has snuffed it.
When one of clients changes some data on server I need to send a message from WCF service to all clients that makes them to download changed data. How can I make that?
You are looking for Publish-subscribe message exchange pattern where all client first have to register on the service (subscribe) when service receives new data it sends them to all other clients (publish).
WCF support this when using duplex communication - Net.Tcp or WSDualHttpBinding. You can check complex artice by Juval Lowy in MSDN magazine.
I have a requirement where a service should be sending a message to client every second. There can be only one client to the service.
I have a created a duplex service and now confused on instance, concurrency and session for the service.
Is session always required for a duplex service? SessionMode.Required
Does the InstanceContextMode should always be PerSession. InstanceContextMode = InstanceContextMode.PerSession?
What should be the ConcurrencyMode?
How can I prevent additional client connection to the service. Should the callback reference in teh client be static and check for null reference when client request is initially received.
I’ll be implementing a heartbeat operation to check the availablity of the service. Should this be a one-way or request reply call and would this call be in same session?
Thanks.
May be I'm late for a few month... If you have only one client and will not have more clients in future, you can use simplest settings: InstanceContextMode.Singleton, SessionMode.NotAllowed.
About ConcurrencyMode you can read in this tutorial: http://codeidol.com/csharp/wcf/Concurrency-Management/Service-Concurrency-Mode/
We have a solution where we are picking the messages using Windows Service.
The Windows Service fires every after 2 minutes and retrieves the MSMQ message to pass it to a Web Service.
Can I create a WCF service which will automatically picks up the messages from MSMQ Queue?
Can I avoid Windows Service by using WCF Service if it support auto invocation?
Q1: you can automatically pick up messages from MSMQ, you will need to look into the netmsmqbinding, there are some design considerations that you have to think about though, if you are used to the native MSMQ, you know that you have the ability to peek at the messages. But when you use WCF, you loose that ability to peek. WCF will intercept the messages in MSMQ and you are responsible for keeping your WCF service and the peeking app in synch.
You will also need to look into whether you need transactional or non-transactional queues and you will have to modify your binding based on that.
Q2: You will need to host the WCF service in windows service or in IIS7. if you host in IIS7 look into enabling MSMQ WAS listener
Here is a nice article:
http://blogs.msdn.com/tomholl/archive/2008/07/12/msmq-wcf-and-iis-getting-them-to-play-nice-part-1.aspx
One way to transfer messages from an MSMQ to a web service call is to use a netMsmqBinding service endpoint and a basicHttpBinding client endpoint that support the same contract. The netMsmq service will automatically grab messages from the queue and deserialize them into an object. In your implementation of your netMsmq service, just instantiate your basicHttp client proxy and just call the same method. Basically a pass-through or proxy pattern from the web-service to the MSMQ and vice-versa. In Juval Lowy's "Programming WCF" he calls this pattern the "HTTP Bridge" for queues.