Call WCF service – error handling & disposing

The final example how to correctly call WCF service and end communication if error occurred:

ServiceClient proxy = null;
bool success = false;
   proxy = new ServiceClient();
   success = true;
   // if failed and not null
   if (!success && proxy != null)

Remember always call Close to end communication. In other case it will can cause to crash server host (IIS for example) after reaching threads or memory limit.

Avoid to call non-IIS WCF service by using the using statement syntax. It will hide the actual communication exceptions details if server side error occurred.

Posted in WCF. Tags: . Leave a Comment »

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: