I want to know how to safely call a WCF web service method. Are both of these methods acceptable/equivalent? Is there a better way?
1st way:
public Thing GetThing()
{
using (var client = new WebServicesClient())
{
var thing = client.GetThing();
return thing;
}
}
2nd way:
public Thing GetThing()
{
WebServicesClient client = null;
try
{
client = new WebServicesClient();
var thing = client.GetThing();
return thing;
}
finally
{
if (client != null)
{
client.Close();
}
}
}
I want to make sure that the client is properly closed and disposed of.
Thanks