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

如何在Bicep中定义使用本地网关的CustomAPI?部署报错求助

解决ManagedApiNotRegisteredForOnPremise错误的Bicep配置修正

针对你遇到的ManagedApiNotRegisteredForOnPremise错误,核心问题是自定义API的配置缺少关键的本地连接标识,同时连接资源的API关联配置有误。以下是具体修正方案:

关键修正点

1. 为Custom API添加本地连接标识

在customApi资源的properties中添加isOnPremise: true属性,这是标记该API支持本地网关连接的必填项——手动创建时门户会自动设置,但Bicep需显式声明:

resource customApi 'Microsoft.Web/customApis@2016-06-01' = {
  name: customApiName
  location: location
  tags: union(tags, { 'azd-service-name': customApiName })
  properties: {
    isOnPremise: true // 新增:标记为本地连接API
    connectionParameters: {
      authType: {
        type: 'string'
      }
      gateway: {
        type: 'gatewaySetting'
      }
    }
    capabilities: [
      'gateway'
    ]
    description: '${customApiName} REST API for on-prem Connection'
    displayName: customApiName
    iconUri: 'https://content.powerapps.com/resource/makerx/static/media/default-connection-icon.00d06b6e.svg'
    apiType: 'Rest'
    swagger: swagger
    backendService: {
      serviceUrl: 'https://mylocalendpoint.com'
    }
  }
}

2. 修正连接资源的API关联配置

连接资源的api对象中,name字段需与自定义API的名称一致,而非连接名称。你当前错误地使用了connectionName,导致系统误判为托管API:

resource connection 'Microsoft.Web/connections@2016-06-01' = {
  name: connectionName
  location: location
  kind: 'V2' // 恢复V2类型,支持本地网关特性
  tags: union(tags, { 'azd-service-name': connectionName })
  properties: {
    displayName: '${connectionName}API-Services Gateway'
    statuses: [
      {
        status: 'Connected'
      }
    ]
    parameterValues: {
      authType: 'anonymous'
      gateway: {
        name: gatewayName
        id: connectionGatewayExternalId
        type: 'Microsoft.Web/connectionGateways'
      }
    }
    api: {
      name: customApi.name // 修正:使用自定义API的名称
      displayName: customApiName
      description: '${customApiName} REST API for on-prem Connection'
      iconUri: 'https://content.powerapps.com/resource/makerx/static/media/default-connection-icon.00d06b6e.svg'
      id: customApi.id
      type: 'Microsoft.Web/customApis'
    }
  }
}

3. 验证Swagger文件配置

确保你的Swagger文件中:

  • host字段指向本地服务的正确地址(无需带协议)
  • schemes配置与本地服务的协议匹配(如本地未配置HTTPS则用http)
  • 无冲突的basePath配置

验证步骤

  1. 确认connectionGatewayExternalId是本地数据网关的有效资源ID,可通过Azure门户获取
  2. 部署后,在Azure门户检查自定义API的支持本地连接选项是否已自动开启
  3. 查看连接资源的状态,确认已成功关联网关和自定义API

内容的提问来源于stack exchange,提问作者pocki_c

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 23:51:13