WCF wrap proxy client

后端 未结 2 1726
春和景丽
春和景丽 2021-01-26 10:12

I have many web method in my projects that used in client application. ]

I don\'t want write code something like this:

 using(ServiceClient sc = new Serv         


        
2条回答
  •  一整个雨季
    2021-01-26 11:01

    I assume you are using Add Service Reference to generate ServiceClient...

    First off, it's not safe to wrap ServiceClient (which derives from ClientBase) in a using block. Here is a stackoverflow thread that goes in depth.

    Second, you can encapsulate the generated ServiceClient and create static methods that do what you are describing, but that's a lot of manual coding for very little benefit. I would instead encourage you to encapsulate the proxy creation, invocation, error handling, closing and disposing in a generic class. This is a good example.

提交回复
热议问题