protected override object Invoke(MethodInfo targetMethod, object[] args) { string serverName = type.GetCustomAttribute <RpcServiceContractAttribute>().Server; string serviceName = !string.IsNullOrEmpty(type.GetCustomAttribute <RpcServiceContractAttribute>().Name) ? type.GetCustomAttribute <RpcServiceContractAttribute>().Name : type.Name; SimpleResponseMessage simpleResponseMessage = null; var task = Task.Run(async() => { var invoker = await invokerFactory.CreateInvokerAsync(serverName); simpleResponseMessage = await invoker.InvokeAsync(serviceName, targetMethod.Name, args); }); task.ContinueWith(t => { if (t.IsFaulted) { throw t.Exception.GetBaseException(); } }).Wait(); return(typeCodec.Decode(new[] { simpleResponseMessage.Result }, new[] { targetMethod.ReturnType }).FirstOrDefault()); }
public string GetSampleEntityPayload(object entity, IEnumerable<string> projectedProperties) { var message = new SimpleResponseMessage(this.StatusCode, this.ContentType); using (var writer = new ODataMessageWriter(message, Settings)) { WriteEntry(writer.CreateODataEntryWriter(), entity, projectedProperties); } return message.GetMessageString(); }
public string GetSamplePropertyPayload(string propertyName, object propertyValue) { var message = new SimpleResponseMessage(this.StatusCode, this.ContentType); using (var writer = new ODataMessageWriter(message, Settings)) { WriteProperty(writer, propertyName, propertyValue); } return message.GetMessageString(); }
public string GetSampleEntityPayload(object entity, IEnumerable <string> projectedProperties) { var message = new SimpleResponseMessage(this.StatusCode, this.ContentType); using (var writer = new ODataMessageWriter(message, Settings)) { WriteEntry(writer.CreateODataEntryWriter(), entity, projectedProperties); } return(message.GetMessageString()); }
public string GetSamplePropertyPayload(string propertyName, object propertyValue) { var message = new SimpleResponseMessage(this.StatusCode, this.ContentType); using (var writer = new ODataMessageWriter(message, Settings)) { WriteProperty(writer, propertyName, propertyValue); } return(message.GetMessageString()); }
public string GetSampleFeedPayload(IEnumerable entities, IEnumerable<string> projectedProperties) { var message = new SimpleResponseMessage(this.StatusCode, this.ContentType); using (var writer = new ODataMessageWriter(message, Settings)) { var feedWriter = writer.CreateODataFeedWriter(); feedWriter.WriteStart(new ODataFeed() { Id = new Uri("http://temp.org/feed"), SerializationInfo = MySerializationInfo }); foreach (var entity in entities) { WriteEntry(feedWriter, entity, projectedProperties); } feedWriter.WriteEnd(); } return message.GetMessageString(); }
protected override void ChannelRead0(IChannelHandlerContext context, SimpleRequestMessage message) { Task.Delay(10).Wait(); if (message != null) { SimpleResponseMessage simpleResponseMessage = new SimpleResponseMessage { ContextID = message.ContextID, MessageID = message.MessageID }; object execRes = null; object[] args = null; try { var executer = this.server.RpcServiceContainer.LookupExecuter(message.ServiceName, message.MethodName); args = typeCodec.Decode(message.Parameters, executer.ArgTypes); execRes = executer.Excute(args); simpleResponseMessage.Success = true; } catch (Exception e) { simpleResponseMessage.Success = false; simpleResponseMessage.ErrorInfo = e.Message; simpleResponseMessage.ErrorDetail = e.StackTrace; } simpleResponseMessage.Result = new SimpleParameter { Value = typeCodec.EnCode(execRes, out int typeCode), ValueType = typeCode }; string pre = $"threadId:{Thread.CurrentThread.ManagedThreadId}-{context.Channel.Id.AsShortText()}"; var log = $"{pre}, Received from client: "; log += $"{Environment.NewLine}{pre}, service: {message.ServiceName}"; log += $"{Environment.NewLine}{pre}, method: {message.MethodName}"; log += $"{Environment.NewLine}{pre}, params:{JsonConvert.SerializeObject(args)}"; log += $"{Environment.NewLine}{pre}, Result: {JsonConvert.SerializeObject(execRes)}"; log += $"{Environment.NewLine}{pre}, Success: {JsonConvert.SerializeObject(simpleResponseMessage.Success)}"; log += $"{Environment.NewLine}{pre}, ErrorInfo: {JsonConvert.SerializeObject(simpleResponseMessage.ErrorInfo)}"; log += $"{Environment.NewLine}{pre}, ErrorDetail: {JsonConvert.SerializeObject(simpleResponseMessage.ErrorDetail)}{Environment.NewLine}"; Logger.Debug(log); context.WriteAndFlushAsync(simpleResponseMessage); } }
public string GetSampleFeedPayload(IEnumerable entities, IEnumerable <string> projectedProperties) { var message = new SimpleResponseMessage(this.StatusCode, this.ContentType); using (var writer = new ODataMessageWriter(message, Settings)) { var feedWriter = writer.CreateODataFeedWriter(); feedWriter.WriteStart(new ODataFeed() { Id = new Uri("http://temp.org/feed"), SerializationInfo = MySerializationInfo }); foreach (var entity in entities) { WriteEntry(feedWriter, entity, projectedProperties); } feedWriter.WriteEnd(); } return(message.GetMessageString()); }