你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

DeviceManagementClient.GetOperationStatus 方法

定义

检索操作状态。

public virtual Azure.Response GetOperationStatus (string operationId, Azure.ETag? ifNoneMatch = default, Azure.RequestContext context = default);
abstract member GetOperationStatus : string * Nullable<Azure.ETag> * Azure.RequestContext -> Azure.Response
override this.GetOperationStatus : string * Nullable<Azure.ETag> * Azure.RequestContext -> Azure.Response
Public Overridable Function GetOperationStatus (operationId As String, Optional ifNoneMatch As Nullable(Of ETag) = Nothing, Optional context As RequestContext = Nothing) As Response

参数

operationId
String

操作标识符。

ifNoneMatch
Nullable<ETag>

定义 If-None-Match 条件。 仅当服务器上的 ETag 与此值不匹配时,才会执行该操作。

context
RequestContext

请求上下文,它可以基于每个调用替代客户端管道的默认行为。

返回

从服务返回的响应。 响应正文架构的详细信息位于下面的“备注”部分。

例外

operationId 为 null。

operationId 是一个空字符串,预期为非空。

服务返回了不成功状态代码。

示例

此示例演示如何使用所需参数调用 GetOperationStatus 并分析结果。

var credential = new DefaultAzureCredential();
var endpoint = new Uri("<https://my-service.azure.com>");
var client = new DeviceManagementClient(endpoint, "<instanceId>", credential);

Response response = client.GetOperationStatus("<operationId>");

JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("operationId").ToString());
Console.WriteLine(result.GetProperty("status").ToString());
Console.WriteLine(result.GetProperty("lastActionDateTime").ToString());
Console.WriteLine(result.GetProperty("createdDateTime").ToString());

此示例演示如何使用所有参数调用 GetOperationStatus,以及如何分析结果。

var credential = new DefaultAzureCredential();
var endpoint = new Uri("<https://my-service.azure.com>");
var client = new DeviceManagementClient(endpoint, "<instanceId>", credential);

Response response = client.GetOperationStatus("<operationId>", null);

JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("operationId").ToString());
Console.WriteLine(result.GetProperty("status").ToString());
Console.WriteLine(result.GetProperty("error").GetProperty("code").ToString());
Console.WriteLine(result.GetProperty("error").GetProperty("message").ToString());
Console.WriteLine(result.GetProperty("error").GetProperty("target").ToString());
Console.WriteLine(result.GetProperty("error").GetProperty("innererror").GetProperty("code").ToString());
Console.WriteLine(result.GetProperty("error").GetProperty("innererror").GetProperty("message").ToString());
Console.WriteLine(result.GetProperty("error").GetProperty("innererror").GetProperty("errorDetail").ToString());
Console.WriteLine(result.GetProperty("error").GetProperty("occurredDateTime").ToString());
Console.WriteLine(result.GetProperty("traceId").ToString());
Console.WriteLine(result.GetProperty("lastActionDateTime").ToString());
Console.WriteLine(result.GetProperty("createdDateTime").ToString());
Console.WriteLine(result.GetProperty("etag").ToString());

注解

下面是响应有效负载的 JSON 架构。

响应正文:

DeviceOperation架构:

{
              operationId: string, # Required. Operation Id.
              status: "NotStarted" | "Running" | "Succeeded" | "Failed", # Required. Operation status.
              error: {
                code: string, # Required. Server defined error code.
                message: string, # Required. A human-readable representation of the error.
                target: string, # Optional. The target of the error.
                details: [Error], # Optional. An array of errors that led to the reported error.
                innererror: {
                  code: string, # Required. A more specific error code than what was provided by the containing error.
                  message: string, # Optional. A human-readable representation of the error.
                  errorDetail: string, # Optional. The internal error or exception message.
                  innerError: InnerError, # Optional. An object containing more specific information than the current object about the error.
                }, # Optional. An object containing more specific information than the current object about the error.
                occurredDateTime: string (ISO 8601 Format), # Optional. Date and time in UTC when the error occurred.
              }, # Optional. Operation error encountered, if any.
              traceId: string, # Optional. Operation correlation identity that can used by Microsoft Support for troubleshooting.
              lastActionDateTime: string (ISO 8601 Format), # Required. Date and time in UTC when the operation status was last updated.
              createdDateTime: string (ISO 8601 Format), # Required. Date and time in UTC when the operation was created.
              etag: string, # Optional. Operation ETag.
            }

适用于