c# - WCF wrap client (static methods which wrap service methods calls) -


possible duplicate:
wcf wrap proxy client

i have many web methods in services in project use client application.

i don't want write code this:

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

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

how static method this:

public static tresult execute<tresult>(func<serviceclient, tresult> proxy) {     using (var client = new serviceclient())     {         return proxy(client);     } } 

and then:

string result1 = execute(proxy => proxy.method1()); int result2 = execute(proxy => proxy.method2("some param", 123)); 

Comments