1)在客户端,您可以将响应(json / xml)解析为强类型类.
here的代码段:
您已在客户端中定义了Product类:
class Product
{
public string Name { get; set; }
public double Price { get; set; }
public string Category { get; set; }
}
然后,您调用API来获取产品并将响应解析为可枚举的产品:
HttpResponseMessage response = client.GetAsync("api/products").Result; // Blocking call!
if (response.IsSuccessStatusCode)
{
// Parse the response body. Blocking!
var products = response.Content.ReadAsAsync>().Result;
foreach (var p in products)
{
Console.WriteLine("{0}\t{1};\t{2}", p.Name, p.Price, p.Category);
}
}
2)ASP .NET Web API基于HTTP.因此,只要您的客户端使用HTTP,您就可以使用Web服务.