tags:

views:

761

answers:

2

I'm writing an App using WCF where clients subscribe to a server and then updates get pushed back to the clients.

The subscribers subscribe to the server using a DuplexPipeChannel calling a Subscribe() method on the server.

The server maintains a List<> of subscribers and when there is data to push out to the subscribers it calls a PushData() method.

My intention is to iterate through the list of subscribers calling the push method on each of them in turn.

What I want to know is: Is calling the push method on my Subscriber blocking? Will a failure of connectivity or delay in connecting to one of the subscribers cause the rest of the push calls to be delayed (or worse fail)?

I'm sorry if this is an obvious question, but I've been mostly a .Net 2.0 person up until now so I know very little about WCF.

My WCF code is loosly based on this tutorial.

Another Question Assuming it is synchronous, am I better off spawning a new thread to deal with the client side requests or would I be better off spawning a new thread for each "push serverside?"

+3  A: 

WCF calls are synchronous by default, although they can be configured to be asynchronous. See Jarrett's answer below. Take a look here. Every message you send will receive a result back, whether you actually are expecting data or not.

The call will block depending on what your server does. If PushData on the server actually iterates through the subscriber list and sends a message to each, it will. If PushData only inserts the data and another thread handles sending the data to the subscribers, it will only block while your server inserts the data and returns.

Hope this helps.

Edit: Regarding spawning threads client-side vs server-side. Server-side. If a client calls takes a while, that's while, but if it takes a long time because the server is actually sending out calls to other clients in the same call, then something is wrong. I would actually not really spawn a new thread each time. Just create a producer/consumer pattern on your server side so that whenever a data item is queued, the consumer picks it up. Hell, you can even have multiple consumers.

siz
+3  A: 

If you right-click on the Service Reference, you have the option to create Async calls. (There's a checkbox on the setup dialog.) I usually create Async methods and then listen for a result. While it is a bit more work, I can write a much more responsive application using async service operations.

Jarrett Meyer
I have updated my response to include this information. +1
siz
I'm creating the service in code how do I make it Asynch in code?
Omar Kooheji