diff --git a/NewLife.Remoting/Clients/ClientBase.cs b/NewLife.Remoting/Clients/ClientBase.cs
index 94988fa..4fcb156 100644
--- a/NewLife.Remoting/Clients/ClientBase.cs
+++ b/NewLife.Remoting/Clients/ClientBase.cs
@@ -5,6 +5,7 @@
using NewLife.Caching;
using NewLife.Log;
using NewLife.Model;
+using NewLife.Net;
using NewLife.Reflection;
using NewLife.Remoting.Models;
using NewLife.Security;
@@ -29,6 +30,10 @@ public abstract class ClientBase : DisposeBase, ICommandClient, IEventProvider,
/// 服务提供者
public IServiceProvider? ServiceProvider { get; set; }
+ private IApiClient? _client;
+ /// Api客户端
+ public IApiClient? Client => _client;
+
/// 是否已登录
public Boolean Logined { get; set; }
@@ -123,6 +128,31 @@ protected virtual void OnInit()
}
PasswordProvider ??= GetService() ?? new SaltPasswordProvider { Algorithm = "md5" };
+
+ if (Client == null)
+ {
+ var urls = Setting?.Server;
+ if (urls.IsNullOrEmpty()) throw new ArgumentNullException(nameof(Setting), "未指定服务端地址");
+
+ _client = urls.StartsWithIgnoreCase("http", "https") ? CreateHttp(urls) : CreateRpc(urls);
+ }
+ }
+
+ /// 创建Http客户端
+ ///
+ ///
+ protected virtual ApiHttpClient CreateHttp(String urls) => new(urls) { Log = Log };
+
+ /// 创建RPC客户端
+ ///
+ ///
+ protected virtual ApiClient CreateRpc(String urls) => new MyApiClient { Client = this, Servers = urls.Split(","), Log = Log };
+
+ class MyApiClient : ApiClient
+ {
+ public ClientBase Client { get; set; } = null!;
+
+ protected override async Task