Below is the complete solution for self hosting of Web API.
static HttpClient client = new HttpClient();
static void Main(string[] args)
{
client.BaseAddress = new Uri("http://admin.xyz.com");
ListAllProducts();
ListProduct(1);
}
static void ListAllProducts()
{
HttpResponseMessage resp = client.GetAsync("api/product").Result;
resp.EnsureSuccessStatusCode();
var products = resp.Content.ReadAsStringAsync().Result;
}
static void ListProduct(int id)
{
var resp = client.GetAsync(string.Format("api/product/{0}", id)).Result;
resp.EnsureSuccessStatusCode();
var product = resp.Content.ReadAsStringAsync().Result;
}
static HttpClient client = new HttpClient();
static void Main(string[] args)
{
client.BaseAddress = new Uri("http://admin.xyz.com");
ListAllProducts();
ListProduct(1);
}
static void ListAllProducts()
{
HttpResponseMessage resp = client.GetAsync("api/product").Result;
resp.EnsureSuccessStatusCode();
var products = resp.Content.ReadAsStringAsync().Result;
}
static void ListProduct(int id)
{
var resp = client.GetAsync(string.Format("api/product/{0}", id)).Result;
resp.EnsureSuccessStatusCode();
var product = resp.Content.ReadAsStringAsync().Result;
}