From e1869d29a4678c7791558ab52e8cc1082561e395 Mon Sep 17 00:00:00 2001 From: moozzyk Date: Tue, 11 Oct 2016 16:17:23 -0700 Subject: [PATCH] fixing single client invocation --- .../SocketsSample/EndPoints/HubEndpoint.cs | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/samples/SocketsSample/EndPoints/HubEndpoint.cs b/samples/SocketsSample/EndPoints/HubEndpoint.cs index c92fa439d5..4c97279831 100644 --- a/samples/SocketsSample/EndPoints/HubEndpoint.cs +++ b/samples/SocketsSample/EndPoints/HubEndpoint.cs @@ -1,12 +1,9 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Threading.Tasks; using Channels; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using Newtonsoft.Json.Linq; using SocketsSample.Hubs; namespace SocketsSample @@ -31,20 +28,6 @@ namespace SocketsSample return new SingleClientProxy(this, connectionId); } - private byte[] Pack(string method, object[] args) - { - var obj = new JObject(); - obj["method"] = method; - obj["params"] = new JArray(args.Select(a => JToken.FromObject(a)).ToArray()); - - if (_logger.IsEnabled(LogLevel.Debug)) - { - _logger.LogDebug("Outgoing RPC invocation method '{methodName}'", method); - } - - return Encoding.UTF8.GetBytes(obj.ToString()); - } - protected override void Initialize(object endpoint) { ((Hub)endpoint).Clients = this; @@ -103,7 +86,22 @@ namespace SocketsSample public Task Invoke(string method, params object[] args) { var connection = _endPoint.Connections[_connectionId]; - return connection?.Channel.Output.WriteAsync(_endPoint.Pack(method, args)); + + var invocationAdapter = _endPoint._serviceProvider.GetRequiredService() + .GetInvocationAdapter((string)connection.Metadata["formatType"]); + + if (_endPoint._logger.IsEnabled(LogLevel.Debug)) + { + _endPoint._logger.LogDebug("Outgoing RPC invocation method '{methodName}'", method); + } + + var message = new InvocationDescriptor + { + Method = method, + Arguments = args + }; + + return invocationAdapter.InvokeClientMethod(connection.Channel.GetStream(), message); } } }