wcf-web-api

Reading content to the memory from the multi-part file upload

巧了我就是萌 提交于 2019-12-22 14:16:34
问题 I have a problem reading uploaded XML file to the string instead of file. My problem is that when I try to access the stream ( var stream = part.ContentReadStream ) then it's closed. I have feeling that it is accessing closed file stream. Am I using MultipartFormDataStreamProvider incorrectly? File size is only few kilobytes, so that should not be a problem. [WebInvoke(Method = "POST", UriTemplate = "{importFile}")] public HttpResponseMessage Upload(string importFile, HttpRequestMessage

Reading content to the memory from the multi-part file upload

烈酒焚心 提交于 2019-12-22 14:16:08
问题 I have a problem reading uploaded XML file to the string instead of file. My problem is that when I try to access the stream ( var stream = part.ContentReadStream ) then it's closed. I have feeling that it is accessing closed file stream. Am I using MultipartFormDataStreamProvider incorrectly? File size is only few kilobytes, so that should not be a problem. [WebInvoke(Method = "POST", UriTemplate = "{importFile}")] public HttpResponseMessage Upload(string importFile, HttpRequestMessage

WCF Web API preview 6: No 'MediaTypeFormatter' is available

元气小坏坏 提交于 2019-12-22 13:02:40
问题 I'm looking at using HttpClient in WCF Web API Preview 6 to consume a third party service. This third party service accepts and returns XML formatted data. Their HTTP responses have the Content-Type header set to text/plain. It appears that having the response Content-Type set to text/plain is causing problems. I'm making the request to the service as follows: Task<HttpResponseMessage> result = client.PostAsync(apiEndpoint, new ObjectContent(typeof (LeaveAccrualRequest), request)); Using

ASP.NET Web Api Routing Customization

穿精又带淫゛_ 提交于 2019-12-21 07:18:25
问题 I have WebApi controllers that end with the "Api" suffix in their names (For ex: StudentsApiController, InstructorsApiController). I do this to easily differentiate my MVC controllers from WebApi controllers. I want my WebApi routes to look similar to http://localhost:50009/api/students/5 and not http://localhost:50009/api/studentsapi/5 . Currently to achieve this, I am setting up routes like routes.MapHttpRoute( name: "GetStudents", routeTemplate: "api/students/{id}", defaults: new {

Ajax Post: 405 Method Not Allowed

风流意气都作罢 提交于 2019-12-20 17:38:18
问题 Within my API Controller called Payment, I have the following method: [HttpPost] public HttpResponseMessage Charge(Payment payment) { var processedPayment = _paymentProcessor.Charge(payment); var response = Request.CreateResponse(processedPayment.Status != "PAID" ? HttpStatusCode.ExpectationFailed : HttpStatusCode.OK, processedPayment); return response; } In my HTML page I have: $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "http://localhost:65396/api/payment

Autofac and IDisposable interface

强颜欢笑 提交于 2019-12-20 12:02:40
问题 Assuming that I have the following interface and class: public interface IFooRepo : IDisposable { //... } public FooRepo : IFooRepo { //Methods here //Properly implement the IDisposbale.Dispose() here } I use Autofac as IoC container in my application and if I register this as below, can I be sure that it will disposed properly? private static IContainer RegisterServices(ContainerBuilder builder) { builder.RegisterType<FooService>().As<IFooService>(); return builder.Build(); } Or should I

WebApi HttpClient for .NET framework 3.5 [closed]

怎甘沉沦 提交于 2019-12-19 06:00:16
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . Is there any package available of WebApi for .Net framework 3.5? I'm specifically looking forward to use HttpClient component of WebApi. Is there any alternatives that work on .Net 3.5? 回答1: A very mature and very robust library that you can use for HTTP Requests is RestSharp. It has support for OAuth, pluggable

Ninject working with WCF Web API Preview 5

我的未来我决定 提交于 2019-12-18 21:28:09
问题 Can anybody point me in the right direction to get Ninject working with WCF Web API Preview 5? I have it successfully up and running in my ASP.NET MVC 3 project and also in another internal WCF Service using the Ninject.Extensions.Wcf library. However I cannot get it to work when creating a new MVC 3 project and getting the WebApi.All library from NuGet. I have looked at this stackoverflow post Setting up Ninject with the new WCF Web API but cannot get it working which I believe could be to

WebApi with EF Code First generates error when having parent child relation

拟墨画扇 提交于 2019-12-18 04:42:34
问题 I am breaking my head over this issue. I did find something on the internet about it, but not a clear answer. My problem: I have to classes in Model section of an MVC3 web app: ParentClass and ChildClass On ParentClass there is a property Children of type List I used EF Code First, which neatly generates a parent table and a child table for me in the database. Now I need a REST service that gives back a List or a single ParentClass. When I remove the property Children from the ParentClass

WebApi with EF Code First generates error when having parent child relation

大憨熊 提交于 2019-12-18 04:42:06
问题 I am breaking my head over this issue. I did find something on the internet about it, but not a clear answer. My problem: I have to classes in Model section of an MVC3 web app: ParentClass and ChildClass On ParentClass there is a property Children of type List I used EF Code First, which neatly generates a parent table and a child table for me in the database. Now I need a REST service that gives back a List or a single ParentClass. When I remove the property Children from the ParentClass