Help Center> ImageSearch> SDK Reference> Using the .NET SDK> Querying Details About an Instance
Updated on 2022-02-22 GMT+08:00

Querying Details About an Instance

This section describes how to query an instance using AK/SK authentication.

Replace the AK/SK in the sample code with the actual AK/SK. Set the InstanceName parameter in the RunQueryInstanceRequest class to specify the name of the instance you want to query. After the configuration is complete, run the code.

  1. The sample code for querying an instance is as follows:
    using System; 
    using System;
    using System.Collections.Generic;
    using HuaweiCloud.SDK.Core;
    using HuaweiCloud.SDK.Core.Auth;
    using HuaweiCloud.SDK.ImageSearch;
    using HuaweiCloud.SDK.ImageSearch.V1;
    using HuaweiCloud.SDK.ImageSearch.V1.Model;
    using Newtonsoft.Json;
     
    namespace RunQueryInstanceSolution
    {
        class Program
        {
            static void Main(string[] args)
            {
                const string ak = "<YOUR AK>";
                const string sk = "<YOUR SK>";
     
                var config = HttpConfig.GetDefaultConfig();
                config.IgnoreSslVerification = true;
                var auth = new BasicCredentials(ak, sk);
     
                var client = ImageSearchClient.NewBuilder()
                        .WithCredential(auth)
                        .WithRegion(ImageSearchRegion.ValueOf("cn-north-4"))
                        .WithHttpConfig(config)
                        .Build();
     
                var req = new RunQueryInstanceRequest
                {
                    InstanceName = "instance-name"
                };
     
                try
                {
                    var resp = client.RunQueryInstance(req);
                    var respStatusCode = resp.HttpStatusCode;
                    Console.WriteLine(respStatusCode);
                    Console.WriteLine(JsonConvert.DeserializeObject(resp.HttpBody));
    
                }
                catch (RequestTimeoutException requestTimeoutException)
                {
                    Console.WriteLine(requestTimeoutException.ErrorMessage);
                }
                catch (ServiceResponseException clientRequestException)
                {
                    Console.WriteLine(clientRequestException.HttpStatusCode);
                    Console.WriteLine(clientRequestException.ErrorCode);
                    Console.WriteLine(clientRequestException.ErrorMsg);
                }
                catch (ConnectionException connectionException)
                {
                    Console.WriteLine(connectionException.ErrorMessage);
                }
            }
        }
    }
  2. Execute the sample code. If the instance querying result is displayed on the console, the code is successfully executed. For details, see Querying the Details About an Instance.
    200 
    {
      "instanceName": "instance-name",
      "level": 30000000,
      "expiredDate": -1,
      "domain": "general image search",
      "domainEn": "General image search",
      "desc": "",
      "registerDate": 1638235929989,
      "tags":[
    "animal",
    "plant"
      ],
      "status": "NORMAL"
    }