C# RESTAPI URI错误

C# RESTAPI URI错误,c#,asp.net-web-api,azure-table-storage,C#,Asp.net Web Api,Azure Table Storage,下面是从Azure表存储(AzureTableHelper.cs)检索数据并以JSON格式显示的代码 请告诉我pid,sid,以及top下面代码的URI的正确格式好吗 正如建议的那样,我尝试了As,但结果是空的。有人能帮我写这个URL吗 许多泰克人提前离开 ValuesController.cs using AzureREST.Models; using System.Web.Http; using System; using Microsoft.WindowsAzure.Storage.Tab

下面是从Azure表存储(AzureTableHelper.cs)检索数据并以JSON格式显示的代码

请告诉我
pid
sid
,以及
top
下面代码的URI的正确格式好吗

正如建议的那样,我尝试了As,但结果是空的。有人能帮我写这个URL吗

许多泰克人提前离开

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;
        }
    }
}
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
使用制度;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.Web.Mvc;
命名空间AzureREST.Controllers
{
公共类HomeController:控制器
{
公共行动结果索引()
{
ViewBag.Title=“主页”;
返回视图();
}
}
}
正如建议的那样,我尝试了As,但结果是空的

由于查询字符串为null,因此在代码中得到的结果为空。在您的例子中,pid、sid和top是url查询字符串。 格式应如下:

http://localhost:51904/api/tracks?pid=ProductionOrder&sid=SerialNumber&top=interNumber
您还可以从中获得有关查询字符串的更多信息

Web框架可以提供解析查询字符串中多个参数的方法,这些参数由一些分隔符分隔。在下面的示例URL中,多个查询参数由符号“&”分隔:

测试结果:

测试Azure表数据


我认为这不是一个与Azure存储相关的问题。感谢卡米洛的编辑!
http://localhost:51904/api/tracks?pid=ProductionOrder&sid=SerialNumber&top=interNumber