diff --git a/NewLife.Remoting/IApiHandler.cs b/NewLife.Remoting/IApiHandler.cs index 341e20d..8566016 100644 --- a/NewLife.Remoting/IApiHandler.cs +++ b/NewLife.Remoting/IApiHandler.cs @@ -198,8 +198,9 @@ public virtual ControllerContext Prepare(IApiSession session, String action, Pac var pis = method.GetParameters(); if (pis == null || pis.Length <= 0) return ps; - // 接口只有一个入参时,客户端可能用基础类型封包传递 - if (pis.Length == 1 && dic == null && args != null) + // 接口只有一个基础类型入参时,客户端可能用基础类型封包传递(字符串)。 + // 例如接口 Say(String text),客户端可用 InvokeAsync("Say", "Hello NewLife!") + if (pis.Length == 1 && pis[0].ParameterType.GetTypeCode() != TypeCode.Object && dic.Count == 0 && args != null) { var pi = pis[0]; ps[pi.Name] = args.ToStr().ChangeType(pi.ParameterType); diff --git a/XUnitTest/ApiTest.cs b/XUnitTest/ApiTest.cs index 70fd209..2c938de 100644 --- a/XUnitTest/ApiTest.cs +++ b/XUnitTest/ApiTest.cs @@ -219,4 +219,36 @@ class SPService public Int64 Test(String key) => _cache.Increment(key, 123); } + + [Fact] + public async void SimpleType() + { + using var server = new ApiServer(12377); + server.Log = XTrace.Log; + server.EncoderLog = XTrace.Log; + server.Register(); + server.Start(); + + using var client = new ApiClient($"tcp://127.0.0.1:{server.Port}"); + + var rs = await client.InvokeAsync("Simple/Say", "Hello NewLife!"); + Assert.Equal("Say: Hello NewLife!", rs); + + var time = DateTime.Now; + rs = await client.InvokeAsync("Simple/Login", time); + Assert.Equal($"Login: {time.ToFullString()}", rs); + + rs = await client.InvokeAsync("Simple/Login", time.ToFullString()); + Assert.Equal($"Login: {time.ToFullString()}", rs); + + rs = await client.InvokeAsync("Simple/Login", time.ToString()); + Assert.Equal($"Login: {time.ToFullString()}", rs); + } + + class SimpleController + { + public String Say(String text) => $"Say: {text}"; + + public String Login(DateTime time) => $"Login: {time.ToFullString()}"; + } } \ No newline at end of file