You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ABP MVC项目报错:Remote service 'Default'未找到及依赖问题

解决ABP项目中“Remote service 'Default' was not found and there is no default configuration”错误

针对你用abp new Acme.BookStore -dbms MySQL -csf创建的ABP解决方案,在实现实体新增功能时遇到的这个错误,按以下步骤排查修复:

1. 检查前端项目的远程服务配置

打开前端项目(独立前端,如Blazor WASM)的wwwroot/appsettings.json,确认RemoteServices节点下存在Default配置,且BaseUrl指向后端API的正确地址(注意端口要和后端启动时的端口一致):

{
  "RemoteServices": {
    "Default": {
      "BaseUrl": "https://localhost:5001" // 替换为你的后端API实际地址
    }
  }
}

2. 确认HttpClient代理注册的正确性

在前端项目的模块类(比如AcmeBookStoreBlazorModule)的ConfigureServices方法中,检查AddHttpClientProxies的remoteServiceName参数是否为"Default",要和配置文件中的键名完全匹配:

public override void ConfigureServices(ServiceConfigurationContext context)
{
    // 其他配置代码...
    
    context.Services.AddHttpClientProxies(
        typeof(AcmeBookStoreApplicationContractsModule).Assembly,
        remoteServiceName: "Default" // 必须与appsettings中的远程服务名称一致
    );
}

3. 配置后端项目的CORS策略(前后端分离场景)

因为你用了-csf创建独立前端,后端需要允许前端的跨域请求:

  • 在后端项目的模块类ConfigureServices中添加CORS配置:
public override void ConfigureServices(ServiceConfigurationContext context)
{
    // 其他配置代码...
    
    context.Services.AddCors(options =>
    {
        options.AddPolicy("AllowFrontend", builder =>
        {
            builder.WithOrigins("https://localhost:5002") // 替换为你的前端项目实际地址
                   .AllowAnyHeader()
                   .AllowAnyMethod()
                   .AllowCredentials();
        });
    });
}
  • 在Configure方法中启用CORS中间件(注意顺序要在UseRouting之后,UseAuthentication之前):
public override void Configure(ServiceConfigurationContext context, IApplicationBuilder app)
{
    // 其他中间件代码...
    
    app.UseRouting();
    app.UseCors("AllowFrontend"); // 启用CORS策略
    app.UseAuthentication();
    app.UseAuthorization();
    
    // 其他中间件代码...
}

4. 验证后端API可用性

启动后端项目,直接在浏览器或API测试工具中访问后端的Participant接口(比如https://localhost:5001/api/participants),确认接口能正常响应,排除后端服务启动失败、端口错误等问题。

5. 确认AppService的远程服务属性

检查ParticipantAppService类是否带有[RemoteService]属性(ABP默认会自动为AppService添加该属性,若手动移除则需重新添加):

[RemoteService]
public class ParticipantAppService : ApplicationService, IParticipantAppService
{
    // AppService实现代码...
}

内容的提问来源于stack exchange,提问作者Serhat Önal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 13:21:26