Click here to Skip to main content
15,887,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I call controller function from web api with patameters. Function called successfully, but parameters are not passed. Whenever function called parameters are null. What i will do for that?

What I have tried:

I checked coding, datatype, web api everything. But it is not work properly. Please help me....
Posted
Updated 31-Oct-16 10:54am
Comments
Suvendu Shekhar Giri 17-Oct-16 3:06am    
Share what have you tried so far? the relevant code blocks
Member 10556393 17-Oct-16 3:22am    
This is my controller function,

[HttpPost]
public HttpResponseMessage Validate(Login login)
{
try
{
Login = new LoginCRUD();

return new HttpResponseMessage()
{
Content = new StringContent(string.Concat(Login.Validate(login)), Encoding.UTF8, "application/json")
};
}
catch (Exception ex)
{
throw ex;
}
}

This is my Class function,

public object Validate(Login login)
{
try
{
DataSet ds = new DataSet();

object[] objParamValue = { login.Password, login.User_Name };

ds = sqlhelper.GetDataset(ConnectionString, "usp_getlogindetails", ProcedureParameters.GetLoginDetailsParameters, objParamValue);
//ds = sqlhelper.GetDataset(ConnectionString, "usp_getlogindetails1", null, null);

return JsonUtility.serializetoJSON(ds.Tables[0]);
}
catch(Exception ex)
{
throw ex;
}
}

F-ES Sitecore 17-Oct-16 5:00am    
Learn to debug your code

http://www.codeproject.com/Articles/79508/Mastering-Debugging-in-Visual-Studio-A-Beginn

Also terms like "not working" are meaningless and don't give any information people can use to try and help you.

1 solution

For anybody to provide you with any help on this (or other issues), you will need to provide better information than you have provided here. A lot of the information provided is not relevant as I understand it you are receiving nulls at the service boundary so the downstream code is not part of the problem - the problem could be how you are invoking the api - have you tested this using a Rest test client (I use a Firefox plugin and/or fiddler)

What does your message look like (I am guessing you are doing a Post) what is the Method, URL, Content-Type and Body...

e.g.

Method : POST URL: http://loalhost:34715/odata/Products
Headers : Content-Type: Application/Json
Body :
{
"ID": 6,
"Description": "Tomato",
"SalePrice": "15",
"ProductGroup": "Vegetable"
}

Providing something like this may help others to help you - I suspect there is an issue with the body of your message that is causing the problem.

One comment on your code - the try catch block is not do anything - if you remove it the code will behave the same as seen from the consumer. Don't catch exceptions unless you are going to do something with them Equally you should not be capturing general exceptions.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900