我想知道如何安全地調用WCF Web服務方法。這兩種方法都可以接受/等同嗎?有沒有更好的辦法?如何在C#中調用Web服務方法
1路:
public Thing GetThing()
{
using (var client = new WebServicesClient())
{
var thing = client.GetThing();
return thing;
}
}
第二個辦法:
public Thing GetThing()
{
WebServicesClient client = null;
try
{
client = new WebServicesClient();
var thing = client.GetThing();
return thing;
}
finally
{
if (client != null)
{
client.Close();
}
}
}
我想,以確保客戶端正常關閉和處置。
感謝
我總是創建WebServicesClient的一個實例,並在整個應用程序實例中使用它,它是否會導致任何問題? – 2010-08-17 11:57:53
謝謝你。沒想到它太複雜了,但這看起來不錯。 – zod 2010-09-10 09:58:36