Null exception after calling Post Request - post

I am building a web api on asp.net. I make requests through client and server. GET and DELETE methods are working properly. When i make POST or PUT i get an error "Response status code does not indicate success: 500 (Internal Server Error)."
Client:
Server:
I used this tutorial.
Why i get a null object (Employee)?

If AddEmployee is an endpoint, then you may need to put the [FromBody] attribute on the parameter.
If it's not an endpoint, then I don't see where AddEmployee is being called. But it looks like the employee parameter is the one that is null. Look up the stack trace, and I bet you'll find someplace where employee is not being set.

I dont know how but when i built a new project the error dissapeared... I used the exact same files and classes.

Related

How to prevent swagger from showing allowed methods?

I realized that when I try to access one of the paths defined in my swagger 2.0 with an incorrect method (ie. GET instead of POST), I receive the following message:
{
"message": "Route defined in Swagger specification (/myPath) but there is no defined get operation.",
"allowedMethods": [
"POST"
]
}
The error message is the same described in this post but my question is quite different. How to get rid of the error in swagger - there is no defined post operation.
I don't want that info to be shown even if I'm not calling to the right method.
I've been looking for any kind of configuration that could remove the "allowedMethods" object from the response. I know this is not the end of the world but I would like not to give away any info about which methods are allowed and which aren't. As a plan Z, I've considered defining any other method for every route with an empty response but that seems a bit overkill, don't you think?
Edit: Server is Nodejs.

SAPUI5 invalid MIME part type with Remote oDATA Service

I need help showing the data from my own remote server with oDATA.
When I want to show the data in the view, I get the following error
invalid MIME part type.
These are the Captures of Error
my https://******/$metadata?
My Table control from SApui5 Course App example
Error when executing the application
And Console error
When I insert this.getModel().setUseBatch(false) in the init : function () of the Component.js, it does not give me the error, nor in the console, but it does not show me the records either .. Can someone give me an idea?
It's an old question, but recently I've got the same error with batch request processing and in my case the root cause was that when building batch processing response with content type multipart/mixed you have to use CRLF as a text line separator ('\r\n') and not only '\n'. See also here in multipart response specification. The hard part was that correct and incorrect responses look absolutely identical when debugging.

ASP.NET WEB API 406 error:for POST request using Media format

I am very new to web api stuff:
I am getting an error
406: Not Acceptable
error message in asp.net web api rest service.
In my rest service I’m using media format for my customized XML output, to get customized output.
I’m registering my formatted media in Global.asax page.
GlobalConfiguration.Configuration.Formatters.Clear();
GlobalConfiguration.Configuration.Formatters.Add(new mynewformat());
all my methods are post methods with typed object as parameter and parameters are accepts from body.
Whenever I try to test the service… Getting 406: Not acceptable error message.
can anyone please help me ... what could be the reason for this....???
I did notice couple of interesting points here...
If I’m commenting below line then I’m getting 200 (OK) status code (which is fine.)... but format is not applying to output.
GlobalConfiguration.Configuration.Formatters.Clear();
If i'm removing parameters in my service method.. Then its working
fine..
I request everyone.. Please guide me what could be the reason/work around/solution/fix..for this issue.
Note:I don't want accept parameters from URI so i made it to accept from frombody only.
Thanks.
There is a lot more to implementing a custom format than just adding it to the configuration formatters. It starts with having to change the media-type header to a new custom type of your choosing (like "application/myNewFormat") for all requests, for the client. On the back end, you have to implement a new MediaTypeFormatter that can handle the serialization. This involves a bit more of code.
A good example of this resides here, it can easily be stripped to boiler-plate code:
http://www.codeproject.com/Articles/559378/Implementing-Custom-Media-Formatters-in-ASP-NET-We

MVC4 WebAPI Reason Phrase?

According to the HttpResponseMessage documentation on MSDN, the reason phrase (as in, the "OK" part of 200 OK) should be settable. The HTTP response does let me set the reason phrase:
HttpResponseMessage response = new HttpResponseMessage(System.Net.HttpStatusCode.Conflict);
response.ReasonPhrase = "conflict message";
However, when I consume the response on the client side as a WebResponse, I don't see my custom reason phrase. I'd expect to find it under the StatusDescription. Looking at the raw response using Fiddler, it doesn't seem that the reason phrase gets set on the server.
A helpful coworker pointed out that with action results (and derived), I could do something akin to:
new HttpStatusCodeResult(System.Net.HttpStatusCode.Conflict, "conflict message");
It seems as though that is the precise functionality I'm after, but I'm uncertain how to convince WebAPI to cooperate.
Where am I going wrong?
The ReasonPhrase does not work in Cassini. Use IIS Express rather than Cassini and you will find that the response includes the reason.

How should asp.net(mvc) server return error to jquery ajax call to be caught in error callback?

Suppose I have a method in my controller that is called via a jQuery AJAX call. E.g. I'd like to delete a user. When everything goes fine, I return new Content('ok') and exit the method.
What should I do when an error occured? I'd like to indicate it by an appropriate status code, so that my error call back would be called called. Why status code? Read here:
How do you trigger the "error" callback in a jQuery AJAX call using ASP.NET MVC?
However, the approach doesn't work because IIS7 returns it's own message (Bad request) insted of my custom error message.
Besides that there are two other catches:
It has to work with IIS6 as well
IE8 doesn't return the 'Bad request' string. Inside error callback the property request.responseTest is null.
The error callback could look like this:
error: function(request) { alert(request.responseText);}
Setting the Response.StatusCode is the correct thing to do. To fix IIS's "helpful" error handling, set the HttpResponse.TrySkipIisCustomErrors property. You can read more about this here.

Resources