JSON.NET as a WebAPI 2 OData serializer vs ODataMediaTypeFormatter

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

WebAPI to Return XML

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

Should ServiceStack be the service layer in an MVC application or should it call the service layer?

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

download csv file from web api in angular js

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

Is there a way to force ASP.NET Web API to return plain text?

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

catch all unhandled exceptions in ASP.NET Web Api

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());

MVC web api: No ‘Access-Control-Allow-Origin’ header is present on the requested resource

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

bahis casinocanlı casino siteleritürkçe altyazılı pornocanlı bahis casino