views:

62

answers:

2

(This relates to Microsoft's SitkaSoapService, in the service reference at https://database.windows.net/soap/v1/)

I'm using SitkaSoapServiceClient to access my SQL Data Services database by SOAP.

Should I use a "using" statement every time I use this proxy class? Or does it do its own connection handling in a safe way internally?

I.e. do I need to say:

using (SitkaSoapServiceClient proxy = GetProxy())
    proxy.Update(scope, entity);

... or is it safe to say:

GetProxy().Update(scope, entity);

[where GetProxy() returns a SitkaSoapServiceClient object.]

A: 

Does the proxy class code compile when wrapped in a using statement? If so, it implements IDisposable and I'd use it.

EDIT: calling Dispose() should incur little overhead if it does nothing, and if the designer of the class decides at a later date to allocate unmanaged resources you will be protected from a leak.

Mitch Wheat
It does implement IDisposable, but I remember there being a similar debate around LinqToSql's DataContext - this implements it too, but the Microsoft brains behind it swore that the "using" was unnecessary.
teedyay
A: 

You should always use using when the class implements IDisposable, because the author of the class tells you that it contains some resources that should be freed.

Grzenio