Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Nov 12, 2012 01:03 AM by danroth27
0 Points
22 Posts
Oct 03, 2012 07:19 AM|LINK
Hi,
I sew lot of sample for ASP WEB API. In althose link the post method is using
HttpResponseMessage as return tyope
can any one tell me Is it possible to use return type bool in WEB API post method?
Any one Please send any sample on this that will helps me.
Member
183 Points
39 Posts
Microsoft
Oct 08, 2012 04:46 PM|LINK
koti.reddy can any one tell me Is it possible to use return type bool in WEB API post method?
Yes. I would recommend you to go through this tutorial:
http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api
The tutorial creates a ApiController called ProductsController which has actions that return different types.
105 Points
97 Posts
Nov 11, 2012 10:42 AM|LINK
Hey Maggie, the link does not help at all. This is what you can get from that tutorial
public class ProductsController : ApiController {
Product[] products = new Product[] { new Product { Id = 1, Name = "Tomato Soup", Category = "Groceries", Price = 1 }, new Product { Id = 2, Name = "Yo-yo", Category = "Toys", Price = 3.75M }, new Product { Id = 3, Name = "Hammer", Category = "Hardware", Price = 16.99M } };
public IEnumerable<Product> GetAllProducts() { return products; }
public Product GetProductById(int id) { var product = products.FirstOrDefault((p) => p.Id == id); if (product == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } return product; }
public IEnumerable<Product> GetProductsByCategory(string category) { return products.Where( (p) => string.Equals(p.Category, category, StringComparison.OrdinalIgnoreCase)); } }
NO POST ACTION
176 Points
41 Posts
Nov 12, 2012 01:03 AM|LINK
Returning bool or any other serializable type from a POST action works just fine. Returning HttpResponseMessage is typically done so that you can also control the headers and status code in addition to the response content.
koti.reddy
0 Points
22 Posts
Hi Is it possible to use return type bool in WEB API post method?
Oct 03, 2012 07:19 AM|LINK
Hi,
I sew lot of sample for ASP WEB API. In althose link the post method is using
HttpResponseMessage as return tyope
can any one tell me Is it possible to use return type bool in WEB API post method?
Any one Please send any sample on this that will helps me.
maggie.ying
Member
183 Points
39 Posts
Microsoft
Re: Hi Is it possible to use return type bool in WEB API post method?
Oct 08, 2012 04:46 PM|LINK
Yes. I would recommend you to go through this tutorial:
http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api
The tutorial creates a ApiController called ProductsController which has actions that return different types.
victorantos
Member
105 Points
97 Posts
Re: Hi Is it possible to use return type bool in WEB API post method?
Nov 11, 2012 10:42 AM|LINK
Hey Maggie, the link does not help at all. This is what you can get from that tutorial
public class ProductsController : ApiController
{
Product[] products = new Product[]
{
new Product { Id = 1, Name = "Tomato Soup", Category = "Groceries", Price = 1 },
new Product { Id = 2, Name = "Yo-yo", Category = "Toys", Price = 3.75M },
new Product { Id = 3, Name = "Hammer", Category = "Hardware", Price = 16.99M }
};
public IEnumerable<Product> GetAllProducts()
{
return products;
}
public Product GetProductById(int id)
{
var product = products.FirstOrDefault((p) => p.Id == id);
if (product == null)
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
return product;
}
public IEnumerable<Product> GetProductsByCategory(string category)
{
return products.Where(
(p) => string.Equals(p.Category, category,
StringComparison.OrdinalIgnoreCase));
}
}
NO POST ACTION
danroth27
Member
176 Points
41 Posts
Microsoft
Re: Hi Is it possible to use return type bool in WEB API post method?
Nov 12, 2012 01:03 AM|LINK
Returning bool or any other serializable type from a POST action works just fine. Returning HttpResponseMessage is typically done so that you can also control the headers and status code in addition to the response content.
Senior Program Manager
ASP.NET