FAQ

This page contains the answers to frequently asked questions.

Communication Patterns

  • What's the best practice for web applications that call services?
Research has shown that in concurrent environments such as web it is more scalable and has better performance to use a dedicated communication object per a sequence of invocations (sequential - one call after another in the same execution chain flow).

It's important to note that for few users, you may notice that using a single communication object to address them all may work faster, however, as soon as more requests come in you should see a noticeable decrease in your application performance, which is bad.

In essence, you should use the singleton instance for single calls or instantiate a new client channel with Sequential/SequentialAsyncOwnChannel to perform a sequence of calls at a given time and dispose it when you're done with it.

Client Channel

  • When should I set the GlobalEndpointName?
ClientChannel<T>.GlobalEndpointName = "myEndpointName";
This needs to be set only once since it's the global name that will be used for all client channels created for the specific 'T' contract.
It is usually placed in the process main entry point.
Note that in WCF Contrib v2.1, if you have a single endpoint in the configuration for the given contract, you don't have to specify the endpoint name at all, it will pick it up automatically.
  • When should I call LoadRuntime?
ClientChannel<T>.LoadRuntime();
This also needs to be called once, it too will usually be placed in the process main entry point.
It is a good practice that you call it whenever you can spare time to load the runtime behavior information, this isn't a necessity though. If you don't call it the infrastructure will automatically load the runtime information upon first access.
  • Is disposing the singleton instance mandatory?
using (ClientChannel<T>.Instance) { }
The implementation of IDisposable in the client channel disposes the channel factory and communication object associated with the client channel.

The necessity of calling the dispose depends on the channel management mode.
The singleton instance is set with SingleCall, this means that behind the scenes upon every call a communication object is created and terminated right after.

That indicates it is not a necessity to call the dispose for such management mode. (The dispose of the factory isn't critical in this point since it just disposes the communication objects associated with it which were already disposed by the client channel infrastructure)

As a general approach, I'd say "If it's IDisposable and you're done with it, dispose it".
If you have control at your application/process exit point and you know which client channels you were using, I don't see a reason not disposing it.

Last edited Feb 10, 2010 at 8:22 PM by zuker, version 2

Comments

No comments yet.