ChannelFactory.Close() vs ChannelFactory.BeginClose()  
Author Message
Helge Kalnes





PostPosted: Windows Communication Foundation ("Indigo"), ChannelFactory.Close() vs ChannelFactory.BeginClose() Top

We're building a web application that is using an application server via WCF web services. The web server is placed in a temporary DMZ with its own rather slow broadband connection serving traffic from the internet, while the application server is to be placed in our ordinary network behind our ordinary firewall. In other words, connections between the two servers will go through the internet with all the trouble that may cause. In about a year or so we will establish a proper DMZ to obtain a more stable and fast connection.

We have chosen to use the generic ChannelFactory class in stead of building client proxies, as this seems to be a more maintainable approach in this case.

When debugging, we have noticed that the ChannelFactory.Close() sometimes takes a little time. Some bright head came up with the idea to use the async approach in stead, by calling ChannelFactory.BeginClose(null, null), which means we initiate a close and do not wait or handle the callback by provide a delegate.

This seems to work out fine in our small test environment. My question is whether this approach is at all advisable, or might cause problems in a production environment with much heavier load.

Thanx in advance for any advice on this!

:) Helge K



Visual Studio 200817  
 
 
Carlos Figueira - MSFT





PostPosted: Windows Communication Foundation ("Indigo"), ChannelFactory.Close() vs ChannelFactory.BeginClose() Top

In general, the contract of asynchronous methods is that you should always call the EndXXX after the callback to BeginXXX is invoked. In this specific case, ChannelFactory.Close() can throw in some scenarios. By not providing any callbacks to BeginClose (and therefore never calling EndClose), you'd never know that the error occurred.


 
 
Helge Kalnes





PostPosted: Windows Communication Foundation ("Indigo"), ChannelFactory.Close() vs ChannelFactory.BeginClose() Top

I see your point, we should at least log any exceptions that could occur during the close operation.

But on the other hand - by the time we are about to call Close(), the "real job" is already done and the user should get his response as quickly as possible. If anything fails during Close(), we should still complete the request as long as we were able to perform whatever we set out to do.

I'll have to rethink this is a bit.

:) HK