如何调试Azure API管理调用中的500错误?
我将我的API连接到Azure的API管理服务。当我尝试调用一个端点时,出现以下错误:如何调试Azure API管理调用中的500错误?,azure,azure-api-management,Azure,Azure Api Management,我将我的API连接到Azure的API管理服务。当我尝试调用一个端点时,出现以下错误: { "statusCode": 500, "message": "Internal server error", "activityId": "79c1bef9-a05d-4734-b729-0657c1749e40" } 我启用了跟踪,这是跟踪json { "traceId": "79c1bef9a05d4734b7290657c1749e40", "traceEntries": {
{
"statusCode": 500,
"message": "Internal server error",
"activityId": "79c1bef9-a05d-4734-b729-0657c1749e40"
}
我启用了跟踪,这是跟踪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."
}
}
]
}
}
“后端服务URL未定义。”邮件对我来说看起来可疑,但我找不到任何关于它们可能意味着什么的信息。如果我不得不猜测的话,我会说API管理在与我真正的API对话时遇到了问题,但我可以直接访问它
有人知道会发生什么事或者我应该看什么吗?我直接通过Azure提供的开发者门户运行测试
Jason在您的Swagger文件中,确保它提到了正确的主机、基本路径和方案条目。 Swashback生成的招摇过市文件往往不包含这些文件 以下是一个例子:
{
"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"
],
请特别关注“主机”、“基本路径”和“方案”,并根据您的API更改它们。我也有同样的问题。我通过将后端API URL放在API管理中API的“Web服务URL”上解决了这个问题。因此,在撰写本文时,使用门户的步骤是:
在API管理中配置端点时,我遇到了类似的错误。当API管理无法验证SSL证书根权限链时,会发生这种情况。如果您使用的是自签名证书,请使用下面的powershell跳过端点的证书链验证
$subscriptionName = "MySubscription"
Get-AzureRmSubscription -SubscriptionName $subscriptionName | Set-AzureRmContext
$context = New-AzureRmApiManagementContext -resourcegroup 'myResourceGroup' -servicename 'myApiManagementServiceName'
New-AzureRmApiManagementBackend -Context $context -Url 'https://myService.abc.com/' -Protocol http -SkipCertificateChainValidation $true
我希望这能解决你的问题
如果需要检查已设置哪些URL以跳过证书链验证,请使用下面的powershell命令-
Get-AzureRmApiManagementBackend -Context $context
最近我遇到了这个问题。使用Swashback.AspNetCore从api创建json文件元数据。由于某种原因,host、schemes、securityDefinitions和apiKeyQuery等字段丢失,原因不明。但在明确添加这些后,问题就解决了。在缺少的字段下面
"host": "your api host .com",
"schemes": ["http", "https"],
"securityDefinitions": {
"apiKeyHeader": {
"type": "apiKey",
"name": "Ocp-Apim-Subscription-Key",
"in": "header"
},
"apiKeyQuery": {
"type": "apiKey",
"name": "subscription-key",
"in": "query"
}
},
"security": [{
"apiKeyHeader": []
}, {
"apiKeyQuery": []
}],
我也有同样的错误,但意识到我有订阅要求,尽管我没有提供任何安全的键值。您能否向我们展示您为这个特定方法在后端策略中设置的转发请求策略?另外:是否还有其他调用在工作,或者这是目前唯一的API调用设置?看起来就像所有的电话都有相同的问题一样。我的后端策略很简单,但我也尝试过。当我从一个不再为我们工作的开发人员那里继承了这个项目时,我在这里摸索着前进。我开始认为问题出在最初的Swagger导入中,因为我试图在别处重新创建API,并从Swagger.json文件中得到错误。该文件由.NET Swashback工具集生成。您的swagger文件是否包含正确的主机和相对uri?是的,这正是问题所在。结果表明,Swashback中的Swagger.json文件不包含Azure API管理中导入所需的主机或方案条目。继续并发布一个答案,我会选择它作为正确的答案。也为我解决了。在这里相同,但为什么?这也让我感到困惑。我们正在使用一个第三方Api,但在我们导入它的Swagger开放Api规范时缺少了这个Api。我也一样。我从一个Azure web应用程序进行了设置,所以我猜默认情况下URL就在那里。谢谢分享!这应该是公认的答案