asp.net-web-api

ASP.NET Core 1.0 Web API doesn't return XML

血红的双手。 提交于 2019-12-29 07:35:26
问题 How can I have my vnext API to return XML and JSON ? I thought that using content-type with application/xml would work as it was before. Note that I tryed with Accept : application/xml too. But it seems not. EDIT : this is my project.json file : { "webroot": "wwwroot", "version": "1.0.0-*", "dependencies": { "Microsoft.AspNet.Server.IIS": "1.0.0-beta4", "Microsoft.AspNet.Server.WebListener": "1.0.0-beta4", "Microsoft.AspNet.Mvc": "6.0.0-beta4", "Microsoft.AspNet.Mvc.Xml": "6.0.0-beta4" },

Entity framework with OData(Web API) is sending Order By clause By default to Sql Query

非 Y 不嫁゛ 提交于 2019-12-29 07:01:11
问题 I am using Web Api with OData. and I have an entity defined in an EF 5.0. I am sending very simple request to Controller:: $.ajax({url: "/odata/Details?$top=10", type: "GET", dataType: 'json', success: function (data) { viewModel.list(data.value); } Now code on My controller:: [Queryable] public override IQueryable<Area> Get() { return db.Area.AsQueryable(); } Query i see using SQL Profiler:: SELECT TOP (@p__linq__1) [Project1].[id] AS [id1], [Project1].[name] AS [name1], [Project1].[pucrhase

ASP.NET MVC 4 Web API fails to map path containing the string “con”?

北城余情 提交于 2019-12-29 06:47:14
问题 What is so wrong about the string "con"? OK, my api route configuration is rather uninteresting: config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); The LocationController has the following method: public List<LocationViewModel> Get(string id) { return _ds.SearchLocations(id); } Everything works as it should, except that I am getting an HTTP 404 error when I try to get the resource like this: /api/location

webapi batching and delegating handlers

余生长醉 提交于 2019-12-29 05:23:04
问题 based on my last post I was able to get batching working... until a certain point. In addition to registering the route specific handler I also have 2 delegating handlers Authenticate the user logging the batch handler goes through the delegating handlers authenticating the user and logging the request. when the messagehandlerinvoker starts to send the child/nested requests the following exception is thrown. System.ArgumentException was unhandled by user code HResult=-2147024809 Message=The

Need to debug my Web API service that's requested from a client machine - need help, how do I do this?

落爺英雄遲暮 提交于 2019-12-29 05:17:51
问题 I built a Web API service that's hosted locally on my machine in IIS. I have an iOS app that I'm running via XCode that makes the call to the web service. The connectivity is there, and works. The iOS app successfully makes the connection to my published web service. The problem is my web service is returning a non descriptive error to the client (iOS), so what I need to be able to do is step through the web service code while running my iOS app. So, in summary: I run an iOS app via my

System.Net.Http.HttpRequestException Error while copying content to a stream

我是研究僧i 提交于 2019-12-29 04:40:50
问题 I am using the HttpClient class in .Net 4.5.2 framework. I am doing a PostAsync to a third party web service. 80% of the time this post works, 20% of the time our response is cut short. In this situation we get the following exception: System.Net.Http.HttpRequestException: Error while copying content to a stream. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException:

How to return Xml Data from a Web API Method?

让人想犯罪 __ 提交于 2019-12-29 04:37:08
问题 I have a Web Api method which should return an xml data but it returns string: public class HealthCheckController : ApiController { [HttpGet] public string Index() { var healthCheckReport = new HealthCheckReport(); return healthCheckReport.ToXml(); } } It returns: <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/"> <myroot><mynode></mynode></myroot> </string> and I have added this mapping: config.Routes.MapHttpRoute( name: "HealthCheck", routeTemplate: "healthcheck", defaults

How to send zip files to ASP.NET WebApi

点点圈 提交于 2019-12-29 04:23:47
问题 I'm wondering how I can send a zip file to a WebApi controller and vice versa. The problem is that my WebApi uses json to transmit data. A zip file is not serializable, either is a stream. A string would be serializable. But there has to be an other solution than to convert the zip into a string and than send the string. That just sounds wrong. Any idea how this is done? 回答1: If your API method expects an HttpRequestMessage then you can pull the stream from that: public HttpResponseMessage

ASP.NET Handle PUT/DELETE verbs

不想你离开。 提交于 2019-12-29 04:21:48
问题 This applies to ASP.NET in general but also Web API. How can we handle PUT/DELETE verbs without enabling RAMMFAR (RunAllManagedModulesForAllRequests). I can't configure the handler mapping within IIS as my site is hosted on an Azure Web Role and any changes I make will not be persisted. 回答1: @Alexander's answer put me on the right track. Had to add the following to get DELETE/PUT handled by ASP.NET: <system.webServer> <modules runAllManagedModulesForAllRequests="false"/> <handlers> <remove

ASP.NET Handle PUT/DELETE verbs

我只是一个虾纸丫 提交于 2019-12-29 04:21:12
问题 This applies to ASP.NET in general but also Web API. How can we handle PUT/DELETE verbs without enabling RAMMFAR (RunAllManagedModulesForAllRequests). I can't configure the handler mapping within IIS as my site is hosted on an Azure Web Role and any changes I make will not be persisted. 回答1: @Alexander's answer put me on the right track. Had to add the following to get DELETE/PUT handled by ASP.NET: <system.webServer> <modules runAllManagedModulesForAllRequests="false"/> <handlers> <remove