WCFを非同期で呼び出す方法に注意すべき点


次のコードを直接使用すると、クライアントオブジェクトが占有するリソースが解放されないため、メモリが漏洩する.GetSimServiceClient client = new GetSimServiceReference.GetSimServiceClient()client.computerSimAsync(DepartmentNo, FileID, F_intput.Length, ReadStringArrayFromStrings());上記の問題は、以下の方法で回避できます.
                    using (GetSimServiceReference.GetSimServiceClient client = new GetSimServiceReference.GetSimServiceClient())

                    {

                        client.computerSimA(DepartmentNo, FileID, F_intput.Length, ReadStringArrayFromStrings());

                    }

しかし、非同期呼び出しを使用すると、リモート・サービスが呼び出されず、異常なヒントがなく、頭がつかめません.
                    using (GetSimServiceReference.GetSimServiceClient client = new GetSimServiceReference.GetSimServiceClient())

                    {

                       client.computerSimAsync(DepartmentNo, FileID, F_intput.Length, ReadStringArrayFromStrings());

                    }

 
最後に、次のコードを使用します.
                    try

                    {

                        GetSimServiceReference.GetSimServiceClient client = new GetSimServiceReference.GetSimServiceClient();

                        client.computerSim(DepartmentNo, FileID, F_intput.Length, ReadStringArrayFromStrings());

                        if (client.State != CommunicationState.Faulted) client.Close();



                    }

                    catch (CommunicationObjectFaultedException cofe)

                    {

                        ShowException.SaveLogAsTXTInfoex("  WCF    ,    :" + cofe.Message);

                    }

                    catch (Exception ex)

                    {

                        ShowException.SaveLogAsTXTInfoex("  WCF    ,    :" + ex.Message+f_intput.FullName);

                    }