405 method not allowed Web API
You are POSTing from the client: await client.PostAsJsonAsync(“api/products”, product); not PUTing. Your Web API method accepts only PUT requests. So: await client.PutAsJsonAsync(“api/products”, product);
You are POSTing from the client: await client.PostAsJsonAsync(“api/products”, product); not PUTing. Your Web API method accepts only PUT requests. So: await client.PutAsJsonAsync(“api/products”, product);
I’ve already figured out my problem and found the solution. OData uses separate media type formatters, inherited from ODataMediaTypeFormatter. Also OData uses different formatters for serialization and deserialization. For replacing this behavior we have to implement descendants of ODataDeserializerProvider and/or ODataSerializerProvider classes and add those classes to the HttpConfiguration.Formatters collections by var odataFormatters = ODataMediaTypeFormatters … Read more
If you don’t want the controller to decide the return object type, you should set your method return type as System.Net.Http.HttpResponseMessage and use the below code to return the XML. public HttpResponseMessage Authenticate() { //process the request ……… string XML=”<note><body>Message content</body></note>”; return new HttpResponseMessage() { Content = new StringContent(XML, Encoding.UTF8, “application/xml”) }; } This is … Read more
You are trying to send a complex object with GET method. The reason this is failing is that GET method can’t have a body and all the values are being encoded into the URL. You can make this work by using [FromUri], but first you need to change your client side code: $.ajax({ url: fullUrl, … Read more
I apologize in advance, this post strays a bit from what you asked, but all of this bubbled up when I read your question. WebAPI Matching Semantic The matching semantic used by (the default routes in) WebAPI is fairly simple. It matches the name of the action with the verb (verb = GET? look for … Read more
I would do neither. Ideally both MVC and ServiceStack should use and share pure C# dependencies. A good example of an MVC + ServiceStack website living harmoniously together is in the SocialBootstrapApi demo project, which has been deployed on AppHarbor at: http://bootstrapapi.apphb.com I would register all your dependencies in your ServiceStack AppHost then register an … Read more
Try it like : File.save(csvInput, function (content) { var hiddenElement = document.createElement(‘a’); hiddenElement.href=”https://stackoverflow.com/questions/20300547/data:attachment/csv,” + encodeURI(content); hiddenElement.target=”_blank”; hiddenElement.download = ‘myFile.csv’; hiddenElement.click(); }); based on the most excellent answer in this question
Hmmm… I don’t think you need to create a custom formatter to make this work. Instead return the content like this: [HttpGet] public HttpResponseMessage HelloWorld() { string result = “Hello world! Time is: ” + DateTime.Now; var resp = new HttpResponseMessage(HttpStatusCode.OK); resp.Content = new StringContent(result, System.Text.Encoding.UTF8, “text/plain”); return resp; } This works for me without … Read more
This is now possible with WebAPI 2.1 (see the What’s New): Create one or more implementations of IExceptionLogger. For example: public class TraceExceptionLogger : ExceptionLogger { public override void Log(ExceptionLoggerContext context) { Trace.TraceError(context.ExceptionContext.Exception.ToString()); } } Then register with your application’s HttpConfiguration, inside a config callback like so: config.Services.Add(typeof(IExceptionLogger), new TraceExceptionLogger()); or directly: GlobalConfiguration.Configuration.Services.Add(typeof(IExceptionLogger), new TraceExceptionLogger());
You need to enable CORS in your Web Api. The easier and preferred way to enable CORS globally is to add the following into web.config <system.webServer> <httpProtocol> <customHeaders> <add name=”Access-Control-Allow-Origin” value=”*” /> <add name=”Access-Control-Allow-Headers” value=”Content-Type” /> <add name=”Access-Control-Allow-Methods” value=”GET, POST, PUT, DELETE, OPTIONS” /> </customHeaders> </httpProtocol> </system.webServer> Please note that the Methods are all individually … Read more