2

ASP.Net MVC 4 - 웹 API에 문제가 있습니다.웹 API에서 작업이 호출되지 않습니다.

내가 내 API 컨트롤러에서 다음과 같은 조치가 : 어떤 이유

public void Post([FromBody] Integration integration) 
{ 
    _repository.Add(integration); 
} 

_repository.Add(integration); 내 중단 점은 결코 통해 온다.

public AuthResponse Post([FromBody] AuthRequest authRequest) 
{ 
    var authResponse = new AuthResponse(); 

    try 
    { 
     . . . 
    } 
    catch (Exception e) 
    { 
     authResponse.Success = false; 
     authResponse.Message = e.Message; 
    } 

    return authResponse; 
} 
: 흥미롭게도

HTTP/1.1 500 Internal Server Error 
Cache-Control: no-cache 
Pragma: no-cache 
Content-Length: 36 
Content-Type: application/json; charset=utf-8 
Expires: -1 
Server: Microsoft-IIS/7.5 
Set-Cookie: ARRAffinity=5d9ceead697ee36c96ed0c04e0e51d80b3f1f3f7fced5c04c89cc370205e464d;Path=/;Domain=ef52667f-3a6e-4a58-b548-e82b72186b5f.o365apps.net 
X-AspNet-Version: 4.0.30319 
X-Powered-By: ASP.NET 
X-Powered-By: ARR/2.5 
X-Powered-By: ASP.NET 
Set-Cookie: WAWebSiteSID=3317c656d3214c81a19cbff73bb5d6cf; Path=/; HttpOnly 
Date: Wed, 20 Mar 2013 20:02:44 GMT 

{"Message":"An error has occurred."} 

, 나는 완벽하게 잘 작동 다른 유사한 방법이있다 : 여기

는 응답이 내가 얻을 수 있습니다 내가 여기에 WebClient

POST https://ef52667f-3a6e-4a58-b548-e82b72186b5f.o365apps.net/api/integration HTTP/1.1 
AccessToken: Vk1Ga4/L/BHYGNY1wVoq3tgGmVlu0YfPukZTlNqnFEK0HH 
Content-Type: application/x-www-form-urlencoded 
Host: ef52667f-3a6e-4a58-b548-e82b72186b5f.o365apps.net 
Content-Length: 334 
Expect: 100-continue 

IntegrationId=c7456461-9e99-4e82-85d5-072670d270b5&Key=2999A604-30C9-423B-8500-8706673EEAFF&ApiUrl=https%3a%2f%2fapi.site.com%2fintegration.asmx&Web=https%3a%2f%2fsiteapp.sharepoint.com%2f&RemoteWeb=https%3a%2f%2ftesting.site.com%2fintegration%2f&ListName=Issues&IncomingAllowed=True&OutgoingAllowed=True&DeletionAllowed=True 

를 사용하여 게시하고있는 무슨이다

여기에 뭔가가 있습니까? 여기에 참고로

, 내 Integration 모델 :

[SharePointList("Integrations")] 
public class Integration : Entity 
{ 
    public Integration(int id) : base(id) { } 

    public Integration() { } 

    [Required] 
    public string ApiUrl { get; set; } 

    [Required] 
    public bool DeletionAllowed { get; set; } 

    [Required] 
    public bool IncomingAllowed { get; set; } 

    [IgnoreDataMember] 
    [Required] 
    public Guid IntegrationId { get; set; } 

    [IgnoreDataMember] 
    [Required] 
    public string Key { get; set; } 

    [Required] 
    public string ListName { get; set; } 

    [Required] 
    public bool OutgoingAllowed { get; set; } 

    [Required] 
    public string RemoteWeb { get; set; } 

    [Required] 
    public string Web { get; set; } 

    public override object this[string property] 
    { 
     get { return GetType().GetProperty(property).GetValue(this, null); } 
     set 
     { 
      if (property.Equals("Id")) throw new Exception("Cannot set Id through an indexer."); 

      if (property.Equals("IntegrationId")) 
      { 
       IntegrationId = new Guid((string) value); 
       return; 
      } 

      if (property.Equals("Title")) 
      { 
       Key = value as string; 
       return; 
      } 

      PropertyInfo propertyInfo = GetType().GetProperty(property); 
      if (propertyInfo == null) throw new Exception(property + " is not a valid property."); 

      propertyInfo.SetValue(this, value, null); 
     } 
    } 
} 

Entity.cs

public abstract class Entity : IEntity 
{ 
    protected Entity(int id) 
    { 
     Id = id; 
    } 

    protected Entity() { } 

    [IgnoreDataMember] 
    public int Id { get; private set; } 

    public abstract object this[string property] { get; set; } 
} 

IEntity.cs

public interface IEntity 
{ 
    int Id { get; } 

    object this[string property] { get; set; } 
} 
+2

예외 세부 정보를 오류에 포함하고 오류 응답을 스택 추적과 공유 할 수 있습니까? 이 [property] (http://msdn.microsoft.com/en-us/library/system.web.http.httpconfiguration.includeerrordetailpolicy (v = vs.108) .aspx)를 사용하여 설정을 변경할 수 있습니다. –

+1

나는 여기에 언급 된 것과 같은 문제가 있다고 확신한다 : http://stackoverflow.com/questions/14499244/problems-with-model-binding-and-validation-attributes-with-asp-net-web -api? lq = 1 – nemesv

+0

이것은 도움이되었습니다. 고마워요. – Moon

답변

0

배치 D 관련 솔루션 클래스/속성 위에 ataContract/DataMember 특성이 문제의 적절한 해결책이 아닙니다. 당신은 WCF의 잔재를 제거하기 위해해야 ​​할 일은

은 다음과 같습니다 SupressRequiredMemberSelector 클래스를 생성

 GlobalConfiguration.Configuration.Services.RemoveAll(typeof(ModelValidatorProvider), v => v is InvalidModelValidatorProvider); 
     GlobalConfiguration.Configuration.Formatters.JsonFormatter.RequiredMemberSelect‌or = new SuppressRequiredMemberSelector(); 

가 :

public class SuppressRequiredMemberSelector : IRequiredMemberSelector 
{ 
    public bool IsRequiredMember(MemberInfo member) 
    { 
     return false; 
    } 
} 

이 해결할 수

당신의 Global.asax이 추가 주석을 변경하지 않고도 문제를 해결할 수 있으며 제공하는 확장 성을 사용하므로 웹 API에 널리 사용되는 "버그 수정"이 가능합니다.

+0

JsonFormatter 만 변경하면 XML을 사용하여 솔루션이 작동합니까? 이것이 "널리 받아 들여지는"버그 수정이라고 언급했습니다. 게시물에 참고 문헌을 추가 할 수 있습니까? – nemesv

+0

주변을 검색 할 수 있지만이 사이트는 afaik로 신고 된 주요 사이트입니다. http://aspnetwebstack.codeplex.com/workitem/270 –