Jas*_*son 4 azure azure-api-management
我将我的API连接到Azure的API Management服务.当我尝试调用我的一个端点时,出现以下错误:
{
"statusCode": 500,
"message": "Internal server error",
"activityId": "79c1bef9-a05d-4734-b729-0657c1749e40"
}
Run Code Online (Sandbox Code Playgroud)
我启用了跟踪,这是跟踪json
{
"traceId": "79c1bef9a05d4734b7290657c1749e40",
"traceEntries": {
"inbound": [
{
"source": "api-inspector",
"timestamp": "2017-10-24T21:50:09.6322945Z",
"elapsed": "00:00:00.0002259",
"data": {
"request": {
"method": "GET",
"url": "https://mysite.azure-api.net/partner/api/partner/ClientsActions",
"headers": [
{
"name": "Ocp-Apim-Subscription-Key",
"value": "..."
},
{
"name": "Connection",
"value": "Keep-Alive"
},
{
"name": "Host",
"value": "mysite.azure-api.net"
}
]
}
}
},
{
"source": "api-inspector",
"timestamp": "2017-10-24T21:50:09.6322945Z",
"elapsed": "00:00:00.0002352",
"data": {
"configuration": {
"api": {
"from": "/partner",
"to": null,
"version": null,
"revision": "1"
},
"operation": {
"method": "GET",
"uriTemplate": "/api/partner/ClientsActions"
},
"user": {
"id": "1",
"groups": [
"Administrators",
"Developers"
]
},
"product": {
"id": "57c59e76ea12f3007f060002"
}
}
}
},
{
"source": "cors",
"timestamp": "2017-10-24T21:50:09.6322945Z",
"elapsed": "00:00:00.0002544",
"data": "Origin header was missing or empty and the request was classified as not cross-domain. CORS policy was not applied."
},
{
"source": "choose",
"timestamp": "2017-10-24T21:50:09.6322945Z",
"elapsed": "00:00:00.0002633",
"data": {
"message": "Expression was successfully evaluated.",
"expression": "context.Request.Url.Query.ContainsKey(\"key\")",
"value": false
}
},
{
"source": "set-header",
"timestamp": "2017-10-24T21:50:09.6322945Z",
"elapsed": "00:00:00.0002744",
"data": {
"message": "Expression was successfully evaluated.",
"expression": "(string)context.User.Id",
"value": "1"
}
},
{
"source": "set-header",
"timestamp": "2017-10-24T21:50:09.6322945Z",
"elapsed": "00:00:00.0002802",
"data": {
"message": "Specified value was assigned to the header (see below).",
"header": {
"name": "x-client-id",
"value": "1"
}
}
}
],
"backend": [
{
"source": "forward-request",
"timestamp": "2017-10-24T21:50:09.6322945Z",
"elapsed": "00:00:00.0002909",
"data": {
"message": "Backend service URL is not defined."
}
},
{
"source": "forward-request",
"timestamp": "2017-10-24T21:50:09.6322945Z",
"elapsed": "00:00:00.0004824",
"data": {
"messages": [
null,
"Backend service URL is not defined."
]
}
}
],
"outbound": [
{
"source": "transfer-response",
"timestamp": "2017-10-24T21:50:09.6322945Z",
"elapsed": "00:00:00.0007989",
"data": {
"message": "Response headers have been sent to the caller."
}
},
{
"source": "transfer-response",
"timestamp": "2017-10-24T21:50:09.6322945Z",
"elapsed": "00:00:00.0008730",
"data": {
"message": "Response body streaming to the caller is complete."
}
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
"未定义后端服务URL".消息看起来很可疑,但我找不到任何有关它们可能含义的信息.如果我不得不猜测我会说API管理问题与我的真实API有关,但我可以直接访问它.
任何人都知道可能会发生什么或我应该看什么?我正在通过Azure提供的开发人员门户直接运行测试.
贾森
小智 12
我遇到过同样的问题.我通过在API管理中将后端API URL放在API的"Web服务URL"上来解决它.因此,在撰写本文时,使用门户网站的步骤将是:
在Swagger文件中,确保它提到正确的主机,basePath和scheme条目.Swashbuckle生成的Swagger文件往往不包含那些.
这是一个例子:
{
"swagger": "2.0",
"info": {
"title": "Your title",
"version": "1.0",
"description": "Your description"
},
"host": "server.host.com",
"basePath": "/api",
"schemes": [
"https"
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
Run Code Online (Sandbox Code Playgroud)
特别关注"host","basePath"和"scheme",并根据您的API更改它们.
| 归档时间: |
|
| 查看次数: |
7297 次 |
| 最近记录: |