/// <summary> /// 释放连接 /// </summary> public void Dispose() { UnConnection(); try { if (baseServiceClient != null) { baseServiceClient.Close(); } if (fileServiceClient != null) { fileServiceClient.Close(); } } catch { if (baseServiceClient != null) { baseServiceClient.Abort(); } if (fileServiceClient != null) { fileServiceClient.Abort(); } } }
static void Main(string[] args) { FileServiceClient client = new FileServiceClient(); String text = "hello"; try { String token = client.OpenFile(); client.WriteToFile(text); client.WriteToFile(text); Console.WriteLine("Result {0}", client.ReadFromFile(text.Length)); Console.ReadLine(); client.CloseFile(token); client.Close(); } catch (TimeoutException timeProblem) { Console.WriteLine("The service operation timed out. " + timeProblem.Message); Console.ReadLine(); client.Abort(); } catch (FaultException <FileAreadyInUseFault> alreadyOpenFault) { Console.WriteLine("The file is already in use. " + alreadyOpenFault.Message); Console.ReadLine(); client.Abort(); } catch (FaultException <FileNotOpenedFault> notOpenedFault) { Console.WriteLine("The file was not opened. " + notOpenedFault.Message); Console.ReadLine(); client.Abort(); } catch (FaultException unknownFault) { Console.WriteLine("An unknown exception was received. " + unknownFault.Message); Console.ReadLine(); client.Abort(); } catch (CommunicationException commProblem) { Console.WriteLine("There was a communication problem. " + commProblem.Message + commProblem.StackTrace); Console.ReadLine(); client.Abort(); } Console.ReadLine(); }
internal void StopFileTransferService() { try { if (_fileServiceClient.State == CommunicationState.Opened) { _fileServiceClient.Close(); } else if (_fileServiceClient.State == CommunicationState.Faulted) { _fileServiceClient.Abort(); } } catch (Exception) { throw; } }