37,950 questions
1218
votes
29
answers
994k
views
How do I get ASP.NET Web API to return JSON instead of XML using Chrome?
Using the newer ASP.NET Web API, in Chrome I am seeing XML - how can I change it to request JSON so I can view it in the browser? I do believe it is just part of the request headers, am I correct in ...
682
votes
18
answers
530k
views
Does IMDB provide an API? [closed]
I recently found a movie organizer application which fetches its data from the IMDB database.
Does IMDB provide an API for this, or any third party APIs available?
505
votes
11
answers
226k
views
WCF vs ASP.NET Web API [closed]
I've spent a few months trying to grasp the concepts behind WCF and recently I've developed my first WCF service application.
I've struggled quite a bit to understand all the settings in the config ...
470
votes
15
answers
778k
views
Best practice to return errors in ASP.NET Web API [closed]
I have concerns on the way that we returns errors to client.
Do we return error immediately by throwing HttpResponseException when we get an error:
public void Post(Customer customer)
{
if (...
410
votes
9
answers
325k
views
Difference between ApiController and Controller in ASP.NET MVC
I've been playing around with ASP.NET MVC 4 beta and I see two types of controllers now: ApiController and Controller.
I'm little confused at what situations I can choose a particular controller.
...
374
votes
9
answers
243k
views
How to add Web API to an existing ASP.NET MVC 4 Web Application project?
I wish to add an ASP.NET Web API to an ASP.NET MVC 4 Web Application project, developed in Visual Studio 2012. Which steps must I perform to add a functioning Web API to the project? I'm aware that I ...
372
votes
9
answers
259k
views
Where is HttpContent.ReadAsAsync?
I see in tons of examples on the web using the new HttpClient object (as part of the new Web API) that there should be HttpContent.ReadAsAsync<T> method. However, MSDN doesn't mention this ...
360
votes
7
answers
443k
views
JWT authentication for ASP.NET Web API
I'm trying to support JWT bearer token (JSON Web Token) in my web API application and I'm getting lost.
I see support for .NET Core and for OWIN applications.
I'm currently hosting my application in ...
348
votes
9
answers
334k
views
Returning binary file from controller in ASP.NET Web API
I'm working on a web service using ASP.NET MVC's new WebAPI that will serve up binary files, mostly .cab and .exe files.
The following controller method seems to work, meaning that it returns a file, ...
327
votes
16
answers
377k
views
HttpClient not supporting PostAsJsonAsync method C#
I am trying to call a web API from my web application. I am using .Net 4.5 and while writing the code I am getting the error HttpClient does not contain a definition PostAsJsonAsync method.
Below is ...
304
votes
13
answers
318k
views
Accessing Session Using ASP.NET Web API
I realize session and REST don't exactly go hand in hand but is it not possible to access session state using the new Web API? HttpContext.Current.Session is always null.
280
votes
32
answers
292k
views
Swagger UI Web Api documentation Present enums as strings?
Is there a way to display all enums as their string value in swagger instead of their int value?
I want to be able to submit POST actions and put enums according to their string value without having ...
275
votes
18
answers
244k
views
Multiple actions were found that match the request in Web Api
I keep getting this error when I try to have 2 "Get" methods
Multiple actions were found that match the request: webapi
I been looking around at the other similar questions about this on stack but ...
264
votes
8
answers
158k
views
Microsoft Web API: How do you do a Server.MapPath?
Since Microsoft Web API isn't MVC, you cannot do something like this:
var a = Request.MapPath("~");
nor this
var b = Server.MapPath("~");
because these are under the System.Web namespace, not the ...
251
votes
6
answers
319k
views
Optional query string parameters in ASP.NET Web API
I need to implement the following WebAPI method:
/api/books?author=XXX&title=XXX&isbn=XXX&somethingelse=XXX&date=XXX
All of the query string parameters can be null. That is, the ...
234
votes
9
answers
357k
views
Put content in HttpResponseMessage object?
Several months ago, Microsoft decided to change up the HttpResponseMessage class. Before, you could simply pass a data type into the constructor, and then return the message with that data, but not ...
226
votes
43
answers
441k
views
Post parameter is always null
Since upgrading to RC for WebAPI I'm having some real odd issue when calling POST on my WebAPI.
I've even gone back to the basic version generated on new project. So:
public void Post(string value)
{
...
224
votes
5
answers
640k
views
How to write a JSON file in C#?
I need to write the following data into a text file using JSON format in C#. The brackets are important for it to be valid JSON format.
[
{
"Id": 1,
"SSN": 123,
"Message": "whatever"
...
218
votes
15
answers
223k
views
How to add/update child entities when updating a parent entity in EF
The two entities are one-to-many relationship (built by code first fluent api).
public class Parent
{
public Parent()
{
this.Children = new List<Child>();
}
public int ...
214
votes
9
answers
293k
views
Specifying a custom DateTime format when serializing with Json.Net
I am developing an API to expose some data using ASP.NET Web API.
In one of the API, the client wants us to expose the date in yyyy-MM-dd format. I don't want to change the global settings (e.g. ...
210
votes
4
answers
249k
views
Why do we have to specify FromBody and FromUri?
Why are the FromBody and FromUri attributes needed in ASP.NET Web API`?
What are the differences between using the attributes and not using them?
205
votes
28
answers
437k
views
Could not load file or assembly 'System.Web.Http 4.0.0 after update from 2012 to 2013
I did the upgrade according to.
http://www.asp.net/mvc/tutorials/mvc-5/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2
I get the error. Does any one else got this ...
200
votes
14
answers
436k
views
Make Https call using HttpClient
I have been using HttpClient for making WebApi calls using C#. Seems neat & fast way compared to WebClient. However I am stuck up while making Https calls.
How can I make below code to make Https ...
195
votes
5
answers
228k
views
Logging request/response messages when using HttpClient
I have a method that does a POST like below
var response = await client.PostAsJsonAsync(url, entity);
if (response.IsSuccessStatusCode)
{
// read the response as strongly typed object
...
194
votes
14
answers
204k
views
prevent property from being serialized in web API
I'm using an MVC 4 web API and asp.net web forms 4.0 to build a rest API. It's working great:
[HttpGet]
public HttpResponseMessage Me(string hash)
{
HttpResponseMessage httpResponseMessage;
...