当前位置: 首页 > 知识库问答 >
问题:

无法从门户获取Azure API应用程序Swagger

金子轩
2023-03-14

我已经创建了一个Azure API应用程序,并将其部署到Azure。起初,我从门户获取Swagger文件没有问题(例如,通过单击API App blade上的“API定义”按钮),但在某个时候,它停止了工作。

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

我尝试过删除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应用程序无法生成有效的虚张声势(或正确执行虚张声威代码)?

共有3个答案

阎宾实
2023-03-14

当部署的版本不起作用时,我使用的流程是。

  1. 设置访问公共-删除网关引入的问题。
  2. 检查已知终端api-https:\|xxxxx\yourapi
  3. 在web.config中打开远程错误
  4. 解决构建中未包含的任何缺失引用(将Copy to Output Directory设置为true)
  5. 重新部署
  6. 访问Swaggerendpoint。
  7. 通过网关重新启用安全性。

这允许您删除多个故障点,并在新的 Api 应用程序中添加额外层之前查看最简单的功能是否有效。

薛望
2023-03-14

最近偶然发现这个应用程序。在启动的配置方法中使用SwaggerUI。cs封装在If Debug编译器指令中。不确定它是开发人员还是自动化模板的一部分,但不值得一提。

习高格
2023-03-14

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

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

我的API应用程序在我将计划更改为标准后就可以工作了。希望这有所帮助!

My API App with Swagger in Azure

有用的参考资料:

创建API应用程序教程

部署 API 应用教程

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

 类似资料:
  • 我已经在谷歌云功能中构建了API。当我试图直接获取API时,会出现CORS错误。虽然我添加了,但失败了。 来自“http://localhost:3000”的“https://xxxxxxxx.com”已被CORS策略阻止:对飞行前请求的响应未通过访问控制检查:请求的资源上没有“access-control-allog-origin”标头。如果一个不透明的响应满足您的需要,请将请求的模式设置为“n

  • 我正在处理使用通知侦听器服务类从通知中读取数据的应用程序。我已完成文本部分,但无法存储通知中收到的图像。 我想存储在WhatsApp应用程序中从通知中收到的图像。我已经尝试了堆栈溢出的所有解决方案,但没有得到任何解决方案。我已经尝试了<代码>通知。EXTRA_PICTURE但它总是返回null。 我见过许多应用程序这样做,但看起来我错过了一些东西。 因此,如果有人能以任何方式提供帮助,我们将不胜感

  • Playstore应用程序中有2个案例 正常安装(Playstore显示打开按钮) 测试用例: 从Firebase动态链接下载应用程序,安装后Playstore将显示“继续”按钮: 有两个选项,用户可以在成功安装后从中打开应用程序。 单击“继续”按钮打开应用程序- 大多数用户没有点击“继续”按钮,因为这是正常的人类行为,因此我失去了“推荐人”链接。 这是Firebase的预期行为吗?如何避免这个问

  • 我在Azure Portal上创建了一个多租户应用程序,并发送请求以获取具有应用程序客户端Id的令牌。我正在使用以下URL在Microsoft Azure AD上获取令牌 https://login.microsoftonline.com/common/oauth2/v2.0/authorize 发送参数为client_id={clientId}的获取请求 但是,它在给定的回调url上返回acce

  • 您可以get get client-go的一个版本,例如get get k8s.io/client-go/1.4/...或者获取k8s.io/client-go/1.4/kubernetes。 现在当我这么做的时候。这是输出- 警告:“k8s.io/client-go/1.4/...”匹配的无包无法加载包:包。:/users/shubhadeeproychowdhury/projects/Go/s