WCF Web サービス メソッドを安全に呼び出す方法を知りたいです。これらの方法は両方とも許容可能/同等ですか? より良い方法はありますか?
最初の方法:
public Thing GetThing()
{
using (var client = new WebServicesClient())
{
var thing = client.GetThing();
return thing;
}
}
2 番目の方法:
public Thing GetThing()
{
WebServicesClient client = null;
try
{
client = new WebServicesClient();
var thing = client.GetThing();
return thing;
}
finally
{
if (client != null)
{
client.Close();
}
}
}
クライアントが適切に閉じられ、処分されていることを確認したい。
ありがとう