如何从单个ID HttpClient Web服务查询中获取某些值

时间:2017-04-22 20:33:55

标签: c# web-services asp.net-web-api uwp httpclient

当我运行以下代码时,我在uriD的所有结果上都返回0,这正确地解析为http://localhost:2463/api/Devices/101070701。我可以从网络浏览器查看这些结果,但不能从我的应用内部查看。

Full Discloser,我确实在我的应用程序中取回了我正在查询的其他表格的所有结果,但这些结果始终是LIST结果。我在零结果查询下面添加了一个。

零结果查询

            var uriD = new Uri("http://localhost:2463/api/Devices/" + HostName);
        HttpClient client = new HttpClient();

        var devices = new Device()
        {
            HostName = HostName,
            DriveSN = DriveSN,
            IP = IP,
            Hardware = Hardware
        };

        try
        {

            var JsonResponseD = await client.GetStringAsync(uriD);
            var devicesResult = JsonConvert.DeserializeObject<Device>(JsonResponseD);
            devices = devicesResult;
        }

成功查询

        var uriC = new Uri("http://localhost:2463/api/Contacts");                    
        var JsonResponseC = await client.GetStringAsync(uriC);
        var contactsResult = JsonConvert.DeserializeObject<List<Contact>>(JsonResponseC);
            Contacts = contactsResult;
单个设备的

JSON响应

{"HostName":101070701,"RouterName":"Test01RA","DriveModel":"Samsung","DriveSN":"123456789","OldDriveSN":"987654321","Server":true,"IP":"10.1.1.1","Gateway":"10.1.1.254","Hardware":"AzureVM","PinPadIP":"10.0.0.100","PreHostName":"PreHost01","EMV":true,"HardwareRole":"Main Register"}

**Interface Image**

1 个答案:

答案 0 :(得分:0)

我错了,我没有设置我的属性,所以他们没有任何回报..

没有结果。属性看起来像这样..

       public int HostName { get; set; }

在我解决之后,他们看起来像这样..

       private int _HostName;
       public int HostName { get { return _HostName; } set { Set(ref _HostName, value); } }