/// <summary> /// 创建异常ResponseData /// </summary> /// <param name="exceptionId"></param> /// <returns></returns> private async Task <ResponseData> CreateServiceExceptionResponseDataAsync(int exceptionId) { var response = protocolStackFactory.CreateServiceResponse(); response.HasException = true; response.ExceptionId = exceptionId; response.ExceptionMessage = ExceptionMap.ServiceExceptions[exceptionId]; return(new ResponseData() { Data = await serializer.SerializeAsync(response) }); }
private static void AddCustomerResponseHandler(ISerializer serializer, byte[] data) { IServiceResponse response = (ServiceResponse)serializer.DeserializeAsync(typeof(ServiceResponse), data).Result; if (response == null) { response = protocolStackFactory.CreateServiceResponse(); } if (response.HasException) { System.Console.WriteLine($"Server has an error, Exception={response.ExceptionId}, ExceptionMessage={response.ExceptionMessage}"); } else { System.Console.WriteLine($"Add customer success"); } }
/// <summary> /// 创建异常ServiceProcessResult /// </summary> /// <param name="exceptionId">异常Id</param> /// <param name="exceptionMessage">异常信息</param> /// <param name="protocolStackFactory">协议栈工厂</param> /// <returns></returns> public static ServiceProcessResult CreateExceptionResult(int exceptionId, string exceptionMessage, IProtocolStackFactory protocolStackFactory) { var response = protocolStackFactory.CreateServiceResponse(); var result = new ServiceProcessResult() { ServiceResponse = response }; response.HasException = true; response.ExceptionId = exceptionId; response.ExceptionMessage = exceptionMessage; return(result); }