WCF Duplex Interaction with Web Server

Posted by Mark Struzinski on Stack Overflow See other posts from Stack Overflow or by Mark Struzinski
Published on 2010-06-16T11:37:09Z Indexed on 2010/06/16 11:42 UTC
Read the original article Hit count: 351

Filed under:

Here is my scenario, and it is causing us a considerable amount of grief at the moment:

We have a vendor web service which provides base level telephony functionality. This service has a SOAP api, which we are leveraging to build up a custom UI that is integrated into our in house web apps. The api functions on 2 levels. You make standard client calls into the service to initiate actions, such as Login, Place Call, Hang Up, etc. On a different thread, the service sends events back to the client to alert the user of things that are occurring on the system (agent successfully logged in, call was disconnected, etc).

I implemented a WCF service to sit between the web server and the vendor service. This WCF service operates in duplex mode, establishing a 2 way connection with the web server. The web server makes outbound calls to the WCF service, which routes them to the vendor's web service. Events are received back to the WCF service, which passes them onto the web server via a callback channel on the WCF client. As events are received on the web server, they are placed into a hash table with the user's name as the key, and a .NET queue as the value to hold the event. Each event is enqueued to the agent who owns it.

On a 2 second interval, the web page polls the web server via an ajax request to get new events for the logged in user. It hits the hash table for the user key, dequeues any events that are present, and serializes them back up to the web page. From there, they are processed in order and appropriate messages are displayed to the user.

This implementation performs well in a single user scenario. The second I put more than 1 user on the system, I start getting frequent timeouts with the following CommunicationException:

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

We are running Windows Server 2008 R2 both servers. Both the web app and WCF service are running on .NET 3.5. The WCF service is running under the net.tcp protocol in duplex mode. The web app is ASP.NET MVC 2.

Has anyone dealt with anything like this scenario? Is there a more efficient way (or a widely accepted pattern) to implement this?

© Stack Overflow or respective owner

Related posts about wcf