/// <summary> /// 向老版本iSeller发出EXPO请求,获取EXPO响应 /// </summary> /// <param name="request">EXPO请求</param> /// <param name="configuration">EXPO响应</param> /// <returns></returns> public ISellerExpoResponse SendMessageToLegencyISeller(ISellerExpoRequest request, LegancyISellerConfiguration configuration) { //构建消息体 var requestMsg = new Message(); requestMsg.SetCommand((ushort)configuration.AppClassId, (uint)configuration.CommandId); byte[] jsonByte = Encoding.Default.GetBytes(request.ConvertToJson()); requestMsg.FillBody(new object[] { jsonByte }, true); var expoSyncMessage = new WindMessageBus.SyncUserMessage(requestMsg); int resultVal = this.appServer.sendMessage(expoSyncMessage, configuration.CommandTimeout); //处理(抛出)异常 if (expoSyncMessage.ErrInfo != null) { throw new WindServiceBusException(expoSyncMessage.ErrInfo); } var responseMsg = expoSyncMessage.Response; if (responseMsg.Header.CommandClass != configuration.AppClassId || responseMsg.Header.CommandValue != configuration.CommandId) { throw new WindServiceBusException("expo response not match request!"); } if (responseMsg.isErrMsg()) { string errorInfo = "unknow expo response exception"; responseMsg.GetErrInfo(out errorInfo); throw new WindServiceBusException(errorInfo); } // 构建消息返回 var expoResponse = responseMsg.ToAnswerObj(); string jsonResult = Encoding.Default.GetString((expoResponse[0] as byte[])); return(ISellerExpoResponse.ConvertFromJson(jsonResult)); }
public void DoCommandStub(CommandHeader header, object[] inputArgs, out object[] outputArgs) { var commandId = header.CommandId; var appClass = header.AppClass; if (commandId == (uint)ExpoCommandName.ServiceBusCommand) { //获取请求输入 var expoInput = new ExpoCommandMessageParser.ExpoMessageInput(inputArgs); try { //处理请求命令 var commandProcessor = this.iocResolver.Resolve <RemoteServiceCommandProcessor>(); var rpcRequest = expoInput.BuidRpcTransportMessage(); //构建请求环境 this.fillRequestRemoteContext(header, rpcRequest.MessageHeader); //处理并返回 var rpcResponse = commandProcessor.ProcessCommand(rpcRequest); //返回命令响应 outputArgs = (new ExpoCommandMessageParser.ExpoMessageOutput(rpcResponse)).BuidExpoMessageBody(); } catch (Exception ex) { //返回异常响应 var serviceUniqueName = new ServiceUniqueNameInfo(expoInput.ServiceAssemblyName, expoInput.ServiceCommandName, ServiceUniqueNameInfo.ServiceMessageType.ServiceCommand); var errorResp = RpcTransportMessageResponse.BuildErrorResponse(serviceUniqueName, RpcTransportResponseCode.SystemError, ex); outputArgs = (new ExpoCommandMessageParser.ExpoMessageOutput(errorResp)).BuidExpoMessageBody(); this.Logger.Error(serviceUniqueName.ToString(), ex); } } else if (commandId == (uint)ExpoCommandName.ServiceBusBroadcastCommand) { //获取请求输入 var expoInput = new ExpoCommandMessageParser.ExpoMessageInput(inputArgs); try { //处理请求命令 var commandProcessor = this.iocResolver.Resolve <RemoteServiceCommandProcessor>(); var rpcRequest = expoInput.BuidRpcTransportMessage(); //构建请求环境 this.fillRequestRemoteContext(header, rpcRequest.MessageHeader); //处理并返回 var rpcResponse = commandProcessor.ProcessBroadcastCommand(rpcRequest); //返回命令响应 outputArgs = (new ExpoCommandMessageParser.ExpoMessageOutput(rpcResponse)).BuidExpoMessageBody(); } catch (Exception ex) { //返回异常响应 var serviceUniqueName = new ServiceUniqueNameInfo(expoInput.ServiceAssemblyName, expoInput.ServiceCommandName, ServiceUniqueNameInfo.ServiceMessageType.ServiceCommand); var errorResp = RpcTransportMessageResponse.BuildErrorResponse(serviceUniqueName, RpcTransportResponseCode.SystemError, ex); outputArgs = (new ExpoCommandMessageParser.ExpoMessageOutput(errorResp)).BuidExpoMessageBody(); this.Logger.Error(serviceUniqueName.ToString(), ex); } } else if (commandId == (uint)ExpoCommandName.ISellerLegacyCommand) { var commandProcessor = this.iocResolver.Resolve <ISellerCommandProcessor>(); string jsonRequest = Encoding.Default.GetString(inputArgs[0] as byte[]); ISellerExpoRequest request = ISellerExpoRequest.ConvertFromJson(jsonRequest); ISellerExpoResponse response = commandProcessor.ProcessCommand(request, messageHeader => { //构建请求环境 this.fillRequestRemoteContext(header, messageHeader); }); outputArgs = new object[] { Encoding.Default.GetBytes(response.ConvertToJson()) }; } else { throw new WindServiceBusException(string.Format("EXPO命令:[{0}]无法识别!", commandId)); } }