WCF Client-Server Synchronization: Polling vs. Binding
I am working on WCF client-server app. where the client has to be constantly synchronized with the server (at least every 10 seconds). At the moment I'm polling the server to see if anything has changed. If so, the changes (sometimes tens of db records) are pulled down to the client.
My design felt a bit clunky so I had a look at how gtalk (and other XMPP) clients keep in-sync. According to this Wikipedia article, the XMPP dropped the polling approach and is now using HTTP binding only.
I presume it is possible to do the same thing for WCF. I think 99% of the WCF apps today simply 1) opens a connection, 2) does the transaction, and 3) closes the connection.
So my questions are:
- Does anyone know of an example of how to implement such an asynchronous binding approa开发者_运维技巧ch with WCF?
- What effect doe that have on the number of clients a server can accommodate, since multiple connections will have to be maintained.
- Any other drawbacks?
Such asynchronnous approach can be implemented by duplex binding. WCF provides WSDualHttpBinding which consists of two corelated http transports. One from the client to the server and second from the server to the client. The approach is to call the server from the client at the beginning of communication. The server stores client callback channel and use it to push updates when needed. This can be futher extended to full Publish Subscribe message exchange pattern.
By default server has to maintain service instance for each connected client proxy (for each session). You have to correctly set up service throttling to allow connection of many clients. The effect on the server and number of clients depends on service implementation.
WSDualHttpBinding has limitations. For example - transport security is not allowed - only message security can be used, streaming is not allowed, reliable session is required, etc. There are some pitfalls in implementation like timeouts in longer inactivity or unhandled exceptions faulting the channel.
精彩评论