I am new to the Web API writing the RESTFul Web Api service in .NET 4. I have set up a controller for the class that I am calling Authentication. The problem I am facing is that when I send or put JSON data to the web api service, my handlers in the controller are called, but the parameter objects have NULL values in them. I can successfully get the data, but Post and Put create empty parameter objects.
I tested the client application and Fiddler and get the same result. Here is what I am sending from Fiddler:
Action: PUT
URI: http://127.0.0.1:81/Authentication/xyz/
HTTP Version: HTTP/1.1
Request Headers:
User-Agent: Fiddler
Host: 127.0.0.1:81
Content-Type: application/json; charset=utf-8
Content-Length: 75
Request Body:
{"hashvalue":"kbVFNeBbNHmYQXXlS6d7Ag==","password":"test","username":"dan"}
When I set a breakpoint in the Put handler in the authentication controller:
public void Put(string IDstring, Authentication value)
{
}
In the viewport, I get the following:
IDstring null string
value {bbsRESTResources.Authentication} bbsRESTResources.Authentication
hashvalue null string
password null string
username null string
my authentication class is as follows:
namespace bbsRESTResources
{
public class Authentication
{
public string username;
public string password;
public string hashvalue;
}
}
my route is as follows:
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
, , . . , , .