>

다음은 Azure 테이블 저장소 (AzureTableHelper.cs)에서 데이터를 검색하고 JSON 형식으로 표시하는 다음 코드입니다.

pid 에 대한 올바른 URI 형식을 알려주시겠습니까? sidtop  아래 코드에 대해?

제안대로 http : // localhost : 51904/api/tracks/ 빈 결과를 제공합니다. 누군가이 URL을 작성하도록 도와 주시겠습니까?

많은 Thaks 사전

ValuesController.cs

using AzureREST.Models;
using System.Web.Http;
using System;
using Microsoft.WindowsAzure.Storage.Table;
using System.Collections.Generic;
using System.Linq;
namespace AzureREST.Controllers
{
    public class TracksController : ApiController
    {
        AzService AzService = new AzService();
        private CloudTable Wndashboard;
        public TracksController()
        {
            Wndashboard = AzService.azManager.Wndashboard;
        }
        // GET api/values        
        public IEnumerable<AzManager.Rc522Entity> Get()
        {
            string pid = "";
            string sid = "";
            int rows = 10;
            var nvc = System.Web.HttpUtility.ParseQueryString(this.Request.RequestUri.OriginalString);
            IList<AzManager.Rc522Entity> rs = new List<AzManager.Rc522Entity>();
            foreach (var item in nvc.AllKeys)
            {
                if (item != null)
                {
                    if (item.Contains("pid"))
                    {
                        if (!string.IsNullOrWhiteSpace(nvc[item]))
                        {
                            pid = nvc[item];
                            TableQuery<AzManager.Rc522Entity> query = new TableQuery<AzManager.Rc522Entity>()
                                .Where(TableQuery.GenerateFilterCondition("ProductionOrder", QueryComparisons.Equal, pid));
                            var retrieved = Wndashboard.ExecuteQuerySegmentedAsync(query, null);
                            if(retrieved.Result.Count()>0)
                                rs.Add(retrieved.Result.Results[0]);
                        }
                    }
                    else if (item.Contains("sid"))
                    {
                        if (!string.IsNullOrWhiteSpace(pid))
                        {
                            if (!string.IsNullOrWhiteSpace(nvc[item]))
                            {
                                sid = nvc[item];
                                TableQuery<AzManager.Rc522Entity> query = new TableQuery<AzManager.Rc522Entity>()
                                    .Where(TableQuery.GenerateFilterCondition("SerialNumber", QueryComparisons.Equal, sid));
                                var retrieved = Wndashboard.ExecuteQuerySegmentedAsync(query, null);
                                if (retrieved.Result.Count() > 0)
                                    rs.Add(retrieved.Result.Results[0]);
                            }
                        }
                    }
                    else if (item.Contains("top"))
                    {
                        if (!string.IsNullOrWhiteSpace(nvc[item]))
                        {
                            rows = Convert.ToInt32(nvc[item]);
                            TableQuery<AzManager.Rc522Entity> query = new TableQuery<AzManager.Rc522Entity>();                                
                            var retrieved = Wndashboard.ExecuteQuerySegmentedAsync(query, null);
                            rs = retrieved.Result.Results.OrderByDescending(x => x.Timestamp).Take(rows).ToList();                             
                        }
                    }
                }
            }
            return rs;
        }
    }
}

WebApiConfig.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
namespace AzureREST
{
    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            // Web API routes
            config.MapHttpAttributeRoutes();
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
        }
    }
}

RouteConfig.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace AzureREST
{
    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }
    }
}

//HomeCOntroller.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace AzureREST.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.Title = "Home Page";
            return View();
        }
    }
}

[! [

//Azure TableHelper.cs
using System;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Table;
namespace AzureREST.Models
{
    public class AzManager
    {
        private class TableManager
        {
            CloudStorageAccount storageAccount;
            CloudTableClient tableClient;
            public TableManager(string connectionString)
            {
                storageAccount = CloudStorageAccount.Parse(connectionString);
                tableClient = storageAccount.CreateCloudTableClient();
            }
            public CloudTable tableById(string id)
            {
                CloudTable table = tableClient.GetTableReference(id);
                table.CreateIfNotExistsAsync();
                return table;
            }
        }
        public class Rc522Entity:TableEntity
        {
            public Rc522Entity(string productionOrder, string serialNumber)
            {
                this.PartitionKey = productionOrder;
                this.RowKey = serialNumber;
            }
            public Rc522Entity()
            {
            }
            //public string PartitionKey { get; set; }
            //public string RowKey { get; set; }
           
           
            public string ProductionOrder { get; set; }
            public string SerialNumber { get; set; }
           
        }
        private TableManager tableManager;
        public CloudTable Wndashboard;
        public AzManager(string connectionString)
        {
            tableManager = new TableManager(connectionString);
            Wndashboard = tableManager.tableById("Wndashboard");
        }
    }
    public class AzService
    {   
        static string storageAccount = "";
        
        static string skey = "";
        static string host = @"https://" + storageAccount + ".table.core.windows.net/";
        static string tableName = "Wndashboard";
        static string resource = string.Format(@"{0}", tableName);
        static string uri = host + resource;
        CloudStorageAccount account = new CloudStorageAccount(new StorageCredentials(storageAccount, skey), true);
        public AzManager azManager = null;
        public AzService()
        {
            azManager = new AzManager("DefaultEndpointsProtocol=https;AccountName="+ storageAccount + ";AccountKey="+skey+";EndpointSuffix=core.windows.net");
        }
    }    
}

  • 답변 # 1

    와이즈 비즈

    쿼리 문자열이 null이므로 코드에 빈 결과가 나타납니다. 귀하의 경우, pid, sid 및 top은 URL 쿼리 문자열입니다. 형식은 다음과 같아야합니다.

    As suggested,I tried as http://localhost:51904/api/tracks/ which gives me empty results

    이 링크에서 쿼리 문자열에 대한 자세한 정보를 얻을 수도 있습니다

    와이즈 비즈

    테스트 결과 :

    Azure 테이블 데이터 테스트

    http://localhost:51904/api/tracks?pid=ProductionOrder&sid=SerialNumber&top=interNumber

  • 이전 leiningen - Clojure에서 명령 줄 인수를 사용하는 방법은 무엇입니까?
  • 다음 c# - 텍스트 파일을 작성하고 작성된 파일이있는 위치를 식별 할 수 없습니다