c# - Azure API App Swagger 无法从门户获得

标签 c# azure azure-web-app-service azure-api-apps

我创建了一个 Azure API 应用程序并将其部署到 Azure。起初,我从门户获取 Swagger 文件没有任何问题(即通过单击 API 应用程序边栏选项卡上的“API 定义”按钮),但在某些时候它停止工作。

我已在 App_Start\SwaggerConfig.cs 中启用了 Swagger UI。当我在本地调试时,我可以导航到 http://localhost:12345/Swagger进入 Swagger UI 并下载 Swagger 文件,一切正常。当我访问门户时,尝试访问 https://microsoft-apiappad6cxxxxxxxxxxxx426c23a66.azurewebsites.net:443/swagger/docs/v1 时收到 500 错误.

我尝试删除 API 应用程序并重新部署它......但没有成功。我尝试过启动一个新项目并使用它创建相同的界面并将其部署到 Azure...每次都有效(当然)。

我将在此处包含 Swagger 文件,以防万一,但我不明白的是:为什么 Swashbuckle 可以在本地工作,但不能在 Azure 中工作?

{
"swagger": "2.0",
"info": {
    "version": "v1",
    "title": "StorefrontApi"
},
"host": "localhost:52912",
"schemes": [
    "http"
],
"paths": {
    "/api/v1/storefront/applications": {
        "get": {
            "tags": [
                "GET"
            ],
            "operationId": "Storefront_Applications",
            "consumes": [],
            "produces": [
                "application/json",
                "text/json",
                "application/xml",
                "text/xml"
            ],
            "responses": {
                "200": {
                    "description": "OK",
                    "schema": {
                        "$ref": "#/definitions/Object"
                    }
                }
            },
            "deprecated": false
        }
    },
    "/api/v1/storefront/aurorastatus": {
        "get": {
            "tags": [
                "GET"
            ],
            "operationId": "Storefront_AuroraStatus",
            "consumes": [],
            "produces": [
                "application/json",
                "text/json",
                "application/xml",
                "text/xml"
            ],
            "parameters": [
                {
                    "name": "auroraSerialNumber",
                    "in": "query",
                    "required": true,
                    "type": "string"
                }
            ],
            "responses": {
                "200": {
                    "description": "OK",
                    "schema": {
                        "$ref": "#/definitions/Object"
                    }
                }
            },
            "deprecated": false
        }
    },
    "/api/v1/storefront/order": {
        "post": {
            "tags": [
                "POST"
            ],
            "operationId": "Storefront_Order",
            "consumes": [
                "application/json",
                "text/json",
                "application/xml",
                "text/xml",
                "application/x-www-form-urlencoded"
            ],
            "produces": [
                "application/json",
                "text/json",
                "application/xml",
                "text/xml"
            ],
            "parameters": [
                {
                    "name": "requestBody",
                    "in": "body",
                    "required": true,
                    "schema": {
                        "type": "string"
                    }
                }
            ],
            "responses": {
                "200": {
                    "description": "OK",
                    "schema": {
                        "$ref": "#/definitions/Object"
                    }
                }
            },
            "deprecated": false
        }
    },
    "/api/v1/storefront/register": {
        "post": {
            "tags": [
                "POST"
            ],
            "summary": "",
            "operationId": "Storefront_Register",
            "consumes": [
                "application/json",
                "text/json",
                "application/xml",
                "text/xml",
                "application/x-www-form-urlencoded"
            ],
            "produces": [
                "application/json",
                "text/json",
                "application/xml",
                "text/xml"
            ],
            "parameters": [
                {
                    "name": "requestBody",
                    "in": "body",
                    "description": "",
                    "required": true,
                    "schema": {
                        "type": "string"
                    }
                }
            ],
            "responses": {
                "200": {
                    "description": "OK",
                    "schema": {
                        "$ref": "#/definitions/Object"
                    }
                }
            },
            "deprecated": false
        }
    },
    "/api/v1/storefront/removeapplication": {
        "post": {
            "tags": [
                "POST"
            ],
            "summary": "",
            "operationId": "Storefront_RemoveApplication",
            "consumes": [
                "application/json",
                "text/json",
                "application/xml",
                "text/xml",
                "application/x-www-form-urlencoded"
            ],
            "produces": [
                "application/json",
                "text/json",
                "application/xml",
                "text/xml"
            ],
            "parameters": [
                {
                    "name": "requestBody",
                    "in": "body",
                    "description": "",
                    "required": true,
                    "schema": {
                        "type": "string"
                    }
                }
            ],
            "responses": {
                "200": {
                    "description": "OK",
                    "schema": {
                        "$ref": "#/definitions/Object"
                    }
                }
            },
            "deprecated": false
        }
    },
    "/api/v1/storefront/updateserialnumber": {
        "post": {
            "tags": [
                "POST"
            ],
            "operationId": "Storefront_UpdateSerialNumber",
            "consumes": [
                "application/json",
                "text/json",
                "application/xml",
                "text/xml",
                "application/x-www-form-urlencoded"
            ],
            "produces": [
                "application/json",
                "text/json",
                "application/xml",
                "text/xml"
            ],
            "parameters": [
                {
                    "name": "requestBody",
                    "in": "body",
                    "required": true,
                    "schema": {
                        "type": "string"
                    }
                }
            ],
            "responses": {
                "200": {
                    "description": "OK",
                    "schema": {
                        "$ref": "#/definitions/Object"
                    }
                }
            },
            "deprecated": false
        }
    }
},
"definitions": {
    "Object": {
        "type": "object",
        "properties": {}
    }
}

}

这当然限制了在逻辑应用程序中使用 API 应用程序的能力,也限制了右键单击/将 Azure API 应用程序客户端添加到我的项目的能力。 (是的,我可以在本地获取Swagger文件,然后在项目中修改并使用它,但这不是我们要寻找的流程)。

有人知道是什么原因导致 API 应用程序无法生成有效的 Swagger(或无法正确执行 Swashbuckle 代码)吗?

最佳答案

尝试转到新的 Azure 门户(预览门户),浏览到您的 API 应用并将应用服务计划/定价层设置为标准

当我第一次使用默认应用服务计划在 Azure 中部署 API 应用程序时,我也遇到了问题,并且在免费计划时似乎没有为 API 应用程序创建实例。

我的 API 应用程序在我将计划更改为标准后即可正常运行。 希望这有帮助!

My API App with Swagger in Azure

有用的引用:

Create API App Tutorial

Deploy API App Tutorial

编辑:答案可以在下面的评论中找到。更新 Swashbuckle NuGet 包后,Swagger 正确显示在 Azure 门户中。

关于c# - Azure API App Swagger 无法从门户获得,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29903227/

相关文章:

c# - .NET 中的错误和异常有什么区别?

c# - Properties.Settings.Default.Save();不在用户机器上保存

c# - 如何在 C# .Net 中显示数据库中的 Highcharts

c# - IE7 和 IE8 兼容的 JQuery 代码行是什么?

Azure DevOps 管道返回 : 'Failed to deploy web package to App Service. Internal Server Error (CODE: 500)'

python - 在azure应用程序服务上使用python 3.6 - 尽管它作为扩展安装,但不起作用

c# - 有没有办法从 azure blob 的容器文件夹中获取所有子文件夹名称?

azure - 更改Azure中Kubernetes创建的资源名称?

android - MSAL Android Xamarin 卡住对话框 ​​- "Are you trying to sign in to {your_appname}"?

azure - Azure Web Apps 架构是什么样的?