I've put an instance of the client proxy for the WCF service into a property on the App class so I can get it from anywhere in the app.
I am not closing the client, I'm leaving it open for the duration of the app. The main reason for this is that if I were to follow the // Comment in the WCF service mex page (the one you get if you point a browser at the WCF service url) it says // Always close the client. client.Close();
which is fine, except if I call client.Close() right after I make a call to client.SomeAsync() method then it's being closed before the results come back. Should I be putting the close into the Completed() method? Or should I just forget about closing it, as once its closed I have to create a new instance of the client proxy (might as well not store it in the App.property if that is the case.
thanks, Stephen
You should close it as advised. And yes, if you're using the async methods then you have to close it only after the call completes.
Creating (opening) and closing clients is the norm for WCF clients. There is no noticeable performance penalty for continuously creating and closing new clients.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With