Reputation: 839
I have a WCF client application that consists of about 5 proxies that all make their own connections throughout the lifecycle of the application. The duration that the client will be running is not long at all (less than 1 minute).
I initially was just calling the method on the proxies when I needed to, which it seems alleviated me from having to call "proxy.Open()". I guess the proxy just opens automatically after the first method call is made.
Now I was wondering if I should explicitly be calling "proxy.Open()" on the proxies before I call a method on them? Additionally, should I open all of them at the start of the client application, especially since the runtime is less than 1 minute? Is there a best practice? I really appreciate your help.
Upvotes: 0
Views: 38
Reputation: 9469
Opening a connection is cheap, so creating proxies every time will not cause major performance issues.
If your exception handling is not 100% bullet-proof, some exceptions can put your proxy in the faulted state. If you keep one proxy for all calls, you will have to check before every call that it is still valid. In this situation, creating new proxies for each call can help you.
Note: fixing the exception handling is still a TODO though.
On the other hand, if your exception handling is robust and FaultException-based, keeping one proxy should be fine.
Upvotes: 0
Reputation: 329
when your proxy will be used in more than thread, invoking Open explicitly is preferable like described in this article.
Upvotes: 2