diff --git a/NewLife.Remoting/Clients/ClientBase.cs b/NewLife.Remoting/Clients/ClientBase.cs
index a7e4c6f..b448d5f 100644
--- a/NewLife.Remoting/Clients/ClientBase.cs
+++ b/NewLife.Remoting/Clients/ClientBase.cs
@@ -47,7 +47,7 @@ public abstract class ClientBase : DisposeBase, ICommandClient, IEventProvider,
/// 收到命令时触发
public event EventHandler? Received;
- /// 命令前缀
+ /// 命令前缀。默认Device/
public String Prefix { get; set; } = "Device/";
/// 协议版本
@@ -84,7 +84,6 @@ protected override void Dispose(Boolean disposing)
/// 参数
///
///
- [return: MaybeNull]
public abstract Task OnInvokeAsync(String action, Object? args, CancellationToken cancellationToken);
/// 远程调用拦截,支持重新登录
diff --git a/NewLife.Remoting/Clients/HttpClientBase.cs b/NewLife.Remoting/Clients/HttpClientBase.cs
index e638ac6..89e973a 100644
--- a/NewLife.Remoting/Clients/HttpClientBase.cs
+++ b/NewLife.Remoting/Clients/HttpClientBase.cs
@@ -1,5 +1,4 @@
-using System.Diagnostics.CodeAnalysis;
-using NewLife.Caching;
+using NewLife.Caching;
using NewLife.Log;
using NewLife.Remoting.Models;
using NewLife.Serialization;
@@ -20,24 +19,32 @@ public class HttpClientBase : ClientBase
///
public ApiHttpClient Client => _client;
- private MyHttpClient _client = null!;
- private ICache _cache = new MemoryCache();
+ private readonly ApiHttpClient _client;
+ private readonly ICache _cache = new MemoryCache();
#endregion
#region 构造
/// 实例化
public HttpClientBase() : base()
{
- _client = new MyHttpClient
+ _client = new ApiHttpClient
{
- Client = this,
Log = XTrace.Log
};
}
/// 实例化
///
- public HttpClientBase(String urls) : this()
+ public HttpClientBase(String urls) : this() => AddServices(urls);
+
+ /// 新增服务点
+ ///
+ ///
+ public void AddService(String name, String url) => _client.Add(name, new Uri(url));
+
+ /// 根据服务端地址列表新增服务点集合
+ ///
+ public void AddServices(String urls)
{
if (!urls.IsNullOrEmpty())
{
@@ -48,11 +55,6 @@ public HttpClientBase(String urls) : this()
}
}
}
-
- /// 新增服务点
- ///
- ///
- public void AddService(String name, String url) => _client.Add(name, new Uri(url));
#endregion
#region 方法
@@ -61,7 +63,6 @@ public HttpClientBase(String urls) : this()
/// 参数
///
///
- [return: MaybeNull]
public override Task OnInvokeAsync(String action, Object? args, CancellationToken cancellationToken)
{
if (args == null || action.StartsWithIgnoreCase("Get") || action.Contains("/Get"))
@@ -70,15 +71,6 @@ public override Task OnInvokeAsync(String action, Object? args
return _client.PostAsync(action, args);
}
- class MyHttpClient : ApiHttpClient
- {
- public HttpClientBase Client { get; set; } = null!;
-
- public Service? Current { get; private set; }
-
- protected override Service GetService() => Current = base.GetService();
- }
-
/// 设置令牌。派生类可重定义逻辑
///
protected override void SetToken(String? token)
diff --git a/NewLife.Remoting/Clients/RpcClientBase.cs b/NewLife.Remoting/Clients/RpcClientBase.cs
index a94432f..ceb2ffa 100644
--- a/NewLife.Remoting/Clients/RpcClientBase.cs
+++ b/NewLife.Remoting/Clients/RpcClientBase.cs
@@ -39,7 +39,6 @@ public RpcClientBase(String urls) : this()
/// 参数
///
///
- [return: MaybeNull]
public override async Task OnInvokeAsync(String action, Object? args, CancellationToken cancellationToken)
{
return await _client.InvokeAsync(action, args, cancellationToken);
diff --git a/Samples/IoTZero/Clients/HttpDevice.cs b/Samples/IoTZero/Clients/HttpDevice.cs
index bdb25f9..99efa69 100644
--- a/Samples/IoTZero/Clients/HttpDevice.cs
+++ b/Samples/IoTZero/Clients/HttpDevice.cs
@@ -22,13 +22,13 @@ public class HttpDevice : HttpClientBase
#region 构造
public HttpDevice() => Prefix = "Device/";
- public HttpDevice(ClientSetting setting) : base(setting.Server)
+ public HttpDevice(ClientSetting setting) : this()
{
- Prefix = "Device/";
-
_setting = setting;
ProductKey = setting.ProductKey;
+
+ AddServices(setting.Server);
}
#endregion