내 winforms 응용 프로그램에서 my asp.net mvc 4 웹 사이트에 개체 목록을 게시하려고합니다. 하나의 객체를 게시 테스트 한 결과 작동하지만 목록에 대해 작동하지 않습니다. 500 (Internal Server Error)
을 반환합니다. 여기 내 코드입니다 :ASP.NET MVC 웹 API : 개체 목록 게시
ASP.NET MVC 웹 API
public class PostTraceController : ApiController
{
public HttpResponseMessage Post(List<WebTrace> list)
{
try
{
// Some code
return Request.CreateResponse(HttpStatusCode.Created);
}
catch (Exception ex)
{
HttpContext.Current.Trace.Write("exception", ex.Message);
return Request.CreateErrorResponse(HttpStatusCode.ServiceUnavailable, ex);
}
}
public HttpResponseMessage Post(WebTrace item)
{
try
{
// Some code
return Request.CreateResponse(HttpStatusCode.Created);
}
catch (Exception ex)
{
HttpContext.Current.Trace.Write("exception", ex.Message);
return Request.CreateErrorResponse(HttpStatusCode.ServiceUnavailable, ex);
}
}
}
상금 응용 프로그램
public class BaseSender
{
public BaseSender()
{
Client = new HttpClient
{
BaseAddress = new Uri(@"http://localhost/mywebsite/")
};
Client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
}
public string UserCode { get; set; }
protected readonly HttpClient Client;
public HttpResponseMessage PostAsJsonAsync(string requestUri, object value)
{
var response = Client.PostAsJsonAsync(requestUri, value).Result;
response.EnsureSuccessStatusCode();
return response;
}
}
public class WebTraceSender : BaseSender
{
private const string requestUri = "api/posttrace";
public bool Post(List<ArchiveCptTrace> list)
{
try
{
var listWebTrace = new List<WebTrace>();
foreach (var item in list)
{
listWebTrace.Add(new WebTrace
{
DateStart = item.DatePreparation,
DateEnd = item.DateCloture,
UserStart = item.UserPreparation.UserName,
UserEnd = item.UserCloture.UserName,
AmountStart = item.MontantPreparation,
AmountEnd = item.MontantCloture,
TheoricAmountEnd = item.MontantTheorique,
Difference = item.Ecart,
UserCode = UserCode
});
}
var responce = PostAsJsonAsync(requestUri, listWebTrace);
return responce.IsSuccessStatusCode;
}
catch (Exception e)
{
// TODO : Trace the exception
return false;
}
}
}
EDIT 형성
나는 api 컨트롤러에 두 가지 메소드를 가지고있는 오류의 시나리오를 발견했습니다. 심지어 다른 서명이 있다고 생각합니다. 하나의 메소드에 주석을 달면 게시물이 잘 작동합니다 (항목 또는 목록). 어떤 아이디어?
500 응답에 오류 메시지가 표시됩니까? 그렇다면 공유 할 수 있습니까? –
@KiranChalla : 아쉽게도 추적 페이지 (localhost/mywebsite/trace.axd)에있는 메시지가 없습니다. – SidAhmed