Tag: asp.net web api

为什么我会得到“文化不受支持”以及如果有什么,我该怎么做呢?

我在这里的“返回”行有一个断点: [HttpGet] [Route(“api/Test/{id1}/{id2}”)] public NRBQEntity GetTestMessage(String id1, String id2) { return NRBQClient.GetTestMessage(id1, id2); } 虽然它没有崩溃应用程序,当我达到这一点,我得到, “ Exception:Thrown:”不支持文化。“(System.Globalization.CultureNotFoundException)抛出了System.Globalization.CultureNotFoundException:”不支持文化。 “ 试图支持哪种文化,为什么不支持这种文化,以及我应该做些什么来支持这种文化? UPDATE 回答斯潘利: 除了代表“BarbeQue的新骑士”之外,它还是一个“骨架”(现在)实体,看起来像这样: public class NRBQEntity { public NRBQEntity() { } public String Value { get; set; } } 更新2 对AnotherUser的回答: 这不是我的代码,所以我只是在试图理解它; 它作为一个起点提供给我复制/重构现有的独立项目,并将其纳入“解决方案”。 已经说过,回答你的问题,这里是解决方案中“GetTestMessage()”的所有实例: [HttpGet] [Route(“api/Test/{id1}/{id2}”)] public NRBQEntity GetTestMessage(String id1, String id2) { return NRBQClient.GetTestMessage(id1, id2); […]

批量请求 – Dynamics CRM

所有, 我正在尝试使用以下源代码向Dynamics CRM实施批处理请求: public async Task HttpPatchCrmApi(string resource, string data) { string uniq = Guid.NewGuid().ToString(); MultipartContent content = new MultipartContent(“mixed”, “batch_” + uniq); HttpRequestMessage batchRequest = new HttpRequestMessage(HttpMethod.Post, CrmBaseUrl + “/api/data/v8.0/$batch”); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, CrmBaseUrl + resource); request.Content = new StringContent(data, Encoding.UTF8, “application/json”); HttpMessageContent query = new HttpMessageContent(request); content.Add(query); batchRequest.Content = content; HttpResponseMessage […]

ModelBindervalidation使用reflection在getter上中断

我遇到了一个似乎与reflection和模型绑定器validation有关的问题,特别是FormatterParameterBinding.ExecuteBindingAsync(..) ,虽然我可以使用一个方法来做我想要的但如果我可以使用我会更喜欢它财产。 在这里,我正在寻找对模型绑定器validation过程的一些见解,为什么我无法做我想做的事情以及如何解决问题,或者解决它。 设置 public class ModelBindingValidationBreaker { public ModelBindingValidationBreaker() { Properties = new List(); } public int A { get; set; } public int B { get; set; } public IList Properties { get; set; } /*// Uncomment to break the model binder validation! public IList PropertyInfos { get { return GetType() .GetProperties() .Where(pi […]

C#异步方法 – 需要帮助

我有一个消耗Web API操作的异步方法。 它似乎陷入了一个循环。 我的理由是因为如果我在catch块的第1行放置一个断点,并且进入,它实际上从未击中第二行。 我最初返回一个包含100,000+(~30mb)行的数据集,并认为由于请求的大小,它可能会很慢,但在更改我的Web API操作以仅返回1行后,问题仍然存在。 当我浏览到Web API解决方案的URI时,肯定会返回数据,我在浏览器中返回了JSON。 public async Task<IEnumerable> GetAll() { try { var response = await _client.GetAsync( string.Format(“{0}/api/document”, _baseURI)); // never hits line below return await response.Content.ReadAsAsync() as IEnumerable; } catch (Exception ex) { // handle exception } } 我不确定我在这里遗失了什么? 一些帮助将不胜感激。 编辑1 在回答一些问题时,我有一个由MVC项目引用的Web API项目。 我必须对JSON反序列化的原始问题进行一些更改。 库: public async Task<IEnumerable> GetAll() { try […]

Route属性中的正则表达式 – RESTful API ASP.NET Web API

我在Route属性中遇到了正则表达式的问题。 我想创建RESTful API,您可以在其中指定URL中的开始日期和结束日期以过滤结果。 我到现在所做的是: [HttpGet] [Route(“date/{startDate:datetime:regex(\\d{4}-\\d{2}-\\d{2})}/{*endDate:datetime:regex(\\d{4}-\\d{2}-\\d{2})}”)] [Route(“date/{startDate:datetime:regex(\\d{4}/\\d{2}/\\d{2})}/{*endDate:datetime:regex(\\d{4}/\\d{2}/\\d{2})}”)] public IEnumerable GetRecommendationByDate(DateTime startDate, DateTime? endDate) { var output = db.Recommendations .Where(r => r.IsPublished == true && r.CreatedDate.CompareTo(startDate) > 0 && r.CreatedDate.CompareTo(endDate.HasValue ? endDate.Value : DateTime.Now) r.LastModified) .ToList(); return output; } 它不是我想要的,因为第二个参数应该是可空的。 当我只通过开始日期时,我得到404.使用斜杠格式也不起作用。 我究竟做错了什么? 我以为*意味着参数可以为空… ===编辑=== 我要匹配的url都是: https:// localhost:post / api / recommendations / date / 10/07/2013 / […]

webapi,如何使用自定义模型绑定器从POST / PUT操作读取文件

我有以下反应组件,显然它的工作正常: import React, { Component } from ‘react’; import { Row, Col } from ‘antd’; import PageHeader from ‘../../components/utility/pageHeader’; import Box from ‘../../components/utility/box’; import LayoutWrapper from ‘../../components/utility/layoutWrapper.js’; import ContentHolder from ‘../../components/utility/contentHolder’; import basicStyle from ‘../../settings/basicStyle’; import IntlMessages from ‘../../components/utility/intlMessages’; import { adalApiFetch } from ‘../../adalConfig’; export default class extends Component { constructor(props) { super(props); this.state […]

无法使用Windows.Web.Http从UWP应用程序发送文件到WebAPI Web服务控制器

我在Windows 10 UWP应用程序上有以下代码,用于将文件发送到WebAPI Web服务。 public async void Upload_FileAsync(string WebServiceURL, string FilePathToUpload) { //prepare HttpStreamContent IStorageFile storageFile = await StorageFile.GetFileFromPathAsync(FilePathToUpload); IRandomAccessStream stream=await storageFile.OpenAsync(FileAccessMode.Read); Windows.Web.Http.HttpStreamContent streamContent = new Windows.Web.Http.HttpStreamContent(stream); //send request var myFilter = new Windows.Web.Http.Filters.HttpBaseProtocolFilter(); myFilter.AllowUI = false; var client = new Windows.Web.Http.HttpClient(myFilter); Windows.Web.Http.HttpResponseMessage result = await client.PostAsync(new Uri(WebServiceURL), streamContent); string stringReadResult = await result.Content.ReadAsStringAsync(); } […]

DELETE方法.NET WebAPI不起作用

我已经看过很多关于这个的post,但我的新WebAPI的DELETE方法根本不起作用,并返回404,使用Windows 7 32位,IIS 7.5。 我试过了 卸载WebDAV 将PUT,DELETE,OPTIONS添加到ExtensionlessUrlHandler-Integrated-4.0处理程序(以及32位/ 64位处理程序)。 允许所有模块运行。 所有都没有用,所有返回404.如果我将DELETE类型更改为GET,那么服务完全运行GET命令。 有没有任何其他想法的人? 这让我疯狂。 编辑: 我正在调用DELETE方法(mediator是jQuery调用的包装器): mediator.publish(“AjaxCall”, { url: “/api/files/” + $(a.currentTarget).data(“fileid”), type: “DELETE”, } }); 和WebAPI: // DELETE api//5 // [HttpDelete] – Tried this too public void Delete(int fileId) { Files.DeleteFile(fileId); } 和相关的web.config:

WebApi自定义filter与构造函数中的注入接口不会被调用

我的问题陈述与此问题相同,即在属性/filter中使用注入服务。 我已经尝试过BZ给出的解决方案,以下是我给出的解决方案的代码。 //marker attribute public class AuthorizeViewAttribute : Attribute { } //filter public class AuthorizeViewFilter : IAuthorizationFilter { private readonly IAccessRightsService _iAccessRightService; public AuthorizeViewFilter(IAccessRightsService iAccessRightService) { _iAccessRightService = iAccessRightService; } public void OnAuthorization(AuthorizationContext filterContext) { RoleFeature roleFeature = _iAccessRightService.GetRoleFeatures(); if (roleFeature.IsView) { //redirect to controller } } } 以下是我使用的ninject绑定: this.BindFilter(System.Web.Mvc.FilterScope.Controller, 0) .WhenControllerHas(); 我不需要属性中的任何参数,所以我想我不需要使用这个答案中提到的WithConstructorArgument 但我的filter永远不会被调用。 我在AuthorizeViewAttribute中放置了一个默认构造函数,调试后发现控件跳转到AuthorizeViewAttribute中的默认构造函数并继续使用控制器方法。 […]

如何将JSON对象读取到WebAPI

我已经检查了一些类似的问题,但没有一个答案似乎适合(或者对我来说足够愚蠢)。 所以,我有一个非常简单的WebAPI来检查数据库中是否存在带有电子邮件的用户。 AJAX: var param = { “email”: “ex.ample@email.com” }; $.ajax({ url: “/api/User/”, type: “GET”, data: JSON.stringify(param), contentType: “application/json; charset=utf-8”, dataType: “json”, success: function (data) { if (data == true) { // notify user that email exists } else { // not taken } } }); 的WebAPI: public bool Get(UserResponse id) { string email = […]