WCF wrap proxy client -


i have many web method in projects used in client application. ]

i don't want write code this:

 using(serviceclient sc = new serviceclient())     {          //invoke service methods                  sc.method1();     } 

instead, want write: serviceclient.method1(); in case common operation reffered proxy initialization, invoking method, disposing, exception processing inside serviceclient. of couse, can wrap of web method similar code or use reflection retriving method name, maybe other ways exist?

i assume using add service reference generate serviceclient...

first off, it's not safe wrap serviceclient (which derives clientbase) in using block. here stackoverflow thread goes in depth.

second, can encapsulate generated serviceclient , create static methods describing, that's lot of manual coding little benefit. instead encourage encapsulate proxy creation, invocation, error handling, closing , disposing in generic class. this example.


Comments