7

Azure API アプリを作成し、Azure にデプロイしました。最初は、ポータルから (つまり、API アプリ ブレードの [API 定義] ボタンをクリックして) Swagger ファイルを問題なく取得できましたが、ある時点で機能しなくなりました。

で Swagger UI を有効にしましたApp_Start\SwaggerConfig.cs。ローカルでデバッグするときは、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 コードを適切に実行できない) 原因について何か考えがある人はいますか?

4

5 に答える 5

0

デプロイされたバージョンが機能しない場合に使用するプロセスは次のとおりです。

  1. パブリックへのアクセスを設定 - ゲートウェイによって引き起こされた問題を削除します。
  2. 既知のエンドポイント API を確認してください - https:\|xxxxx\yourapi
  3. web.config でリモート エラーを有効にする
  4. ビルドに含まれていない不足参照を解決します ([出力ディレクトリへのコピー] を true に設定します)。
  5. 再デプロイ
  6. Swagger エンドポイントにアクセスします。
  7. ゲートウェイ経由のセキュリティを再度有効にします。

これにより、複数の障害点を取り除き、新しい API アプリに余分なレイヤーを追加する前に、最も単純な機能が機能するかどうかを確認できます。

于 2015-05-06T20:33:50.200 に答える
0

私は同じ問題を抱えていましたが、サービスプランをアップグレードしてナゲットパッケージを更新することで解決しました。

于 2016-02-05T17:10:41.900 に答える