Do I have to check if it has already been closed before calling Close () in the WCF service?

Before I call Close()WCF in my service, should I check if it is still closed?

i.e.

myWCFService.State != System.ServiceModel.CommunicationState.Closed

My code looks like this:

MyServiceClient myWCFClient = null;

try
{
  myWCFClient = new .....();
}
catch
{
}
finally
{
   myWCFClient.Close();
}
+3
source share
2 answers

The WCF client is one-time, so, with the exception of a few caveats, you can use using:

using(MyClient client = new MyClient()) {
    client.DoStuff();
    // etc
}

But there is a big problem with this; Disposeon the client, WCF actually throws if it is erroneous (losing the original exception). There is a good workaround here , or I wrote a blog post about this.

+2
source

: WCF using? , , .

+1

Source: https://habr.com/ru/post/1703954/


All Articles