How Do I: Avoid Deadlock Situations in a Web Service?

There are many situations in which deadlocks can be created between communicating web services. However, following this rule will keep you out of trouble most of the time:

Never invoke a synchronous method on the caller to a synchronous method.

When a client invokes a synchronous method on a web service, the client will block waiting for the method to complete. If you attempt to call the client (invoke a callback) while the client is waiting for the original method to complete, then each party will waiting for the other. This is deadlock. The same situation could occur if a callback handler attempted to call a synchronous method on it's caller.

If you have a situation where you want to invoke a callback from a method, you can avoid deadlock by making either the method or the callback asynchronous. One simple way to make the method or callback asynchronous is to use message buffering.

To Buffer a Method or Callback

1. In Design View, select the method or callback.

2. In the Properties pane, expand the message-buffer property.

3. From the drop-down list next to the enable attribute, select true.

# Related Topics

Using Asynchrony to Enable Long-Running Operations