What is the best workaround for the WCF client `using` block issue?

前端 未结 26 2139
余生分开走
余生分开走 2020-11-22 00:03

I like instantiating my WCF service clients within a using block as it\'s pretty much the standard way to use resources that implement IDisposable:

26条回答
  •  孤城傲影
    2020-11-22 00:13

    I like this way of closing connection:

    var client = new ProxyClient();
    try
    {
        ...
        client.Close();
    }
    finally
    {
        if(client.State != CommunicationState.Closed)
            client.Abort();
    }
    

提交回复
热议问题