英文:
Can't load webapi from App Service in APi Management
问题
我们正在Azure中设置API管理实例,并希望将.NET Core 5中开发的WebApi的定义集成为一个App Service。
问题在于,当我们尝试直接将API加载为AppService时,方法定义未加载,而每个HTTP动词都显示为通用方法。
我们尝试将其加载为OPENApi定义,定义被加载,但似乎它没有与真实的App Service链接,因为我们通过Postman对AppService进行的外部调用在API管理监控中看不到。
我不知道我们做错了什么。
我们尝试将以下内容添加到startup.cs:
var swaggerOptions = new SwaggerOptions();
Configuration.GetSection(nameof(SwaggerOptions)).Bind(swaggerOptions);
app.UseSwagger(option =>
{
option.RouteTemplate = swaggerOptions.JsonRoute;
option.SerializeAsV2 = true; // 这是可选的,用于控制Swagger版本
});
app.UseSwaggerUI(option =>
{
option.SwaggerEndpoint(swaggerOptions.UIEndpoint, swaggerOptions.Description);
});
感谢帮助。
英文:
We are setting up an APi Management instance in Azure and we want it to integrate the definitions of a WebApi developed in .NET Core5 and published as an App Service.
The problem is that when we try to directly load the API as AppService, the method definitions are not loaded, and a generic method appears for each HTTP verb.
We have tried loading it as OPENApi Definition, and the definitions are loaded but it gives us the impression that it does not link with the real app service, since the calls that we make externally by postman to the appservice are not seen in the API Management monitoring
I don't know what we are doing wrong.
We have tried adding the following to startup.cs
var swaggerOptions = new SwaggerOptions();
Configuration.GetSection(nameof(SwaggerOptions)).Bind(swaggerOptions);
app.UseSwagger(option =>
{
option.RouteTemplate = swaggerOptions.JsonRoute;
option.SerializeAsV2 = true; // this is optional to control the swagger version
});
app.UseSwaggerUI(option =>
{
option.SwaggerEndpoint(swaggerOptions.UIEndpoint, swaggerOptions.Description);
});
Thanks for the help
答案1
得分: 1
请查看以下加载API的步骤:
在从Visual Studio部署应用程序后,转到Azure门户中的API管理。
所有操作都将在“测试”选项卡下可用。
- 单击“API” => “所有API” => “测试”,然后选择要执行的操作。
AppService .NET Core 5的输出:
由于.NET Core 5已不再受支持,因此可能无法按预期工作。
建议您迁移到.NET Core 6
。
请参考此SOThread以使用.NET Core 6 API。
英文:
Check the below steps to load the API's
After deploying the app from Visual Studio,Navigate to the API Management in the Azure Portal.
All the operations will be available under the Test
tab.
- Click on
API
=>All API's
= >Test
and select an operation which you want to execute.
Output from AppService .NET Core 5:
As .NET Core 5 is Out of Support, it may not work as expected.
Advice you to migrate to .NET Core 6
.
Refer this SOThread to Work with .NET Core 6 API.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论