asp.net-web-api

Getting JSON Serialization Entity Framework Self Reference Loop error even after ProxyCreation false when using explicit Include

北城以北 提交于 2020-01-01 03:22:05
问题 JSON Serialization (ASP.Net Web API) fails because of self-referencing loop (it’s a common problem, Reason: an entity being requested lazy loads child entities and every child has a back reference to parent entity). Work around I found, but doesn’t help me: Use [JsonIgnore] for navigation properties to be ignored: This solution works but doesn’t apply in my case. For Example: To get a Customer information along with his Orders, I would quickly add [JsonIgnore] to Customer property in Order

ASP.Net Web API vs WCF, which one should I choose in my project

若如初见. 提交于 2020-01-01 02:53:08
问题 I have read many articles in the web so far, about the differences between WCF and ASP.Net web API. Unfortunately I could not come up to a clear idea about what will serve my purpose. Most of the Articles I have read highlighted on the design point of view of the two web services. But I am confused what will work best for my project and why? Here is my brief description of the project. I need to create a communication channel between two servers (both are written in C#). The servers will

HttpClient and PushStreamContent

删除回忆录丶 提交于 2020-01-01 02:36:14
问题 I use PushStreamContent with my REST API (ASP.NET Web API) and works great. The HttpClient can request a ressource and gets the HTTP-Response before the complete request is handled by the server (the server still writes to the push-stream). As HttpClient you have to do one little thing: Use HttpCompletionOption.ResponseHeadersRead. Now my question: Is it possible to to this the other way? From the HttpClient -> uploading data via a push-stream to the web api? I Implemented it as below, but

best practice for using async await in webapi

北城余情 提交于 2020-01-01 02:34:14
问题 I have .NET core Web API which as service layer. Service layer has all EF code. If have basecontroller with this code protected Task<IActionResult> NewTask(Func<IActionResult> callback) { return Task.Factory.StartNew(() => { try { return callback(); } catch (Exception ex) { Logger.LogError(ex.ToString()); throw; } }); } In controller action I wrap all calls to service in above method e.g. : [HttpGet("something")] public async Task<IActionResult> GetSomething(int somethingId) { return await

How to apply custom validation to JWT token on each request for ASP.NET WebApi?

99封情书 提交于 2020-01-01 02:34:10
问题 Is it possible to add custom validation to each request when authenticating web api calls using a bearer token? I'm using the following configuration and the application already validates the JWT tokens correctly. app.UseOAuthAuthorizationServer(new OAuthAuthorizationServerOptions { AuthenticationType = "jwt", TokenEndpointPath = new PathString("/api/token"), AccessTokenFormat = new CustomJwtFormat(), Provider = new CustomOAuthProvider(), }); app.UseJwtBearerAuthentication(new

How to return a list of objects as an IHttpActionResult?

吃可爱长大的小学妹 提交于 2020-01-01 02:29:33
问题 I'm new to ASP.NET webapi and I can't find a way to return a list of objects queried by id. This is my controller method for the GET request. I want to return all the questions which have a specified questionnaireId passed via url. I tried this: // GET: api/Questions/5 [ResponseType(typeof(List<Question>))] public Task<IHttpActionResult> GetQuestion(int questionnaireId) { var questions = from q in db.Questions where q.QuestionnaireId == questionnaireId select new Question() { Id = q.Id,

BuildManager.GetReferencedAssemblies equivalent for non-web applications

你。 提交于 2020-01-01 02:09:05
问题 Compared to AppDomain.GetAssemblies() , BuildManager.GetReferencedAssemblies() (System.Web.Compilation.BuildManager) seems a more reliable way to get the assemblies that are referenced by an ASP.NET application at runtime, since AppDomain.GetAssemblies() only gets "the assemblies that have already been loaded into the execution context of this application domain". Iterating through all assemblies is an important tool for dynamically registering types at application start-up in your DI

asp web api patch implementation

穿精又带淫゛_ 提交于 2020-01-01 01:30:11
问题 Assume i have this model public partial class Todo { public int id { get; set; } public string content { get; set; } public bool done { get; set; } } And i send this as json data to my controller as a patch request. This is mearly the action of toggeling a checkbox. I think it makes sence that i only want to sent that to my server, and not the entire model. { "id":1, "done" : true } What does my WebApi controller need to look like in order to correctly process this, simple, json patch request

Calling another Web API controller directly from inside another Web API controller

我怕爱的太早我们不能终老 提交于 2019-12-31 16:13:47
问题 Given a controller Proxy and an action of GetInformation . I want to be able to call the method GetInformation of the Users controller. Both the WebAPI controllers are in the same project but direct calls like var controller = new UsersController(); return controller.GetInformation(request); Doesn't work. The signature is: public HttpResponseMessage GetInformation(InformationRequest request) I do not want to do a full redirect response as I do not want the UserController route exposed

Calling another Web API controller directly from inside another Web API controller

こ雲淡風輕ζ 提交于 2019-12-31 16:13:34
问题 Given a controller Proxy and an action of GetInformation . I want to be able to call the method GetInformation of the Users controller. Both the WebAPI controllers are in the same project but direct calls like var controller = new UsersController(); return controller.GetInformation(request); Doesn't work. The signature is: public HttpResponseMessage GetInformation(InformationRequest request) I do not want to do a full redirect response as I do not want the UserController route exposed