Breeze의 JsonMediaTypeFormatter
설정에 문제가 있습니다. 내가하는 것은 WebAPI 에 의해 보내고받는 json의 날짜가 항상 UTC에서 작동한다는 것입니다.Breeze의 WebApi 컨트롤러가 UTC DateTime과 함께 작동하는 방식은 무엇입니까?
는 this document에 따르면, 그것은 작동하지 않았다 그러나 JsonSerializerSettings
에 대한 DateTimeZoneHandling.Utc
에 재산 DateTimeZoneHandling
을 설정함으로써 가능할 것이다.
this source code을 조사한 결과,이 동작에 영향을 미칠 수있는 것이 this other issue에 대해 수행 된 해킹임을 깨달았습니다.
이 코드를 모두 제거하면 모든 것이 정상적으로 작동합니다.
//jsonSerializerSettings.Converters.Add(new IsoDateTimeConverter
//{
// DateTimeFormat = "yyyy-MM-dd\\THH:mm:ss.fffK"
//});
어떻게 해킹을 제거하지 않고도이 상황을 처리 할 수 있습니까?
var jsonFormatter = Breeze.WebApi.JsonFormatter.Create();
jsonFormatter.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
jsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/json"));
jsonFormatter.SupportedEncodings.Add(new UTF8Encoding(false, true));
GlobalConfiguration.Configuration.Formatters.Insert(
0, jsonFormatter);
을하지만이 반환 된 날짜는 UTC에 없었다, 작동하지 않았다 다음과 같이 설정
EDIT 1
내 첫 번째 시도였다.
편집 2
첫째, 나는 0.80.3 버전으로 바람 lib에 업데이트되었습니다. 내 App_Start 폴더에서
나는이 BreezeWebApiConfig.cs 파일이 있습니다
[assembly: WebActivator.PreApplicationStartMethod(
typeof(Partner.App_Start.BreezeWebApiConfig), "RegisterBreezePreStart")]
namespace Partner.App_Start
{
public static class BreezeWebApiConfig
{
public static void RegisterBreezePreStart()
{
GlobalConfiguration.Configuration.Routes.MapHttpRoute(
name: "BreezeApi",
routeTemplate: "api/{controller}/{action}"
);
var jsonFormatter = Breeze.WebApi.JsonFormatter.Create();
jsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/json"));
jsonFormatter.SupportedEncodings.Add(new UTF8Encoding(false, true));
GlobalConfiguration.Configuration.Formatters.Insert(
0, jsonFormatter);
// Apply query parameters, expressed as OData URI query strings,
// to results of Web API controller methods that return IQueryable<T>
GlobalConfiguration.Configuration.Filters.Add(
new Breeze.WebApi.ODataActionFilter());
}
}
}
둘째, 내가 생성 한 CustomBreezeConfig.cs 클래스를 내가 BreezeConfig라는 폴더에 (제이 아래에 설명 된 코드) 그러나이 새로운 시도는 효과가 없었습니다.
감사합니다,
베르나르도 파 체코
해결 되었으면 알려주십시오. 그렇다면 대답 아래의 체크 표시를 확인하십시오. 이렇게하면이 문제를 해결하는 데 도움이됩니다. 고마워. – Ward
@Jay 동일한 코드 (위에서 설명한 BreezeWebApiConfig.cs 클래스와 CustomBreezeConfig.cs 클래스)를 유지하고 v 0.80.5로 업데이트했습니다. 그러나 서버에서 클라이언트로 보낸 json 날짜는 여전히 UTC가 아닙니다 (끝에 Z가 없음). 문안 인사. –
Bernardo, 그렇지는 않지만 클라이언트에서 올바르게 변환됩니다 (UTC 날짜로). DataType.parseDateFromServer 메서드가 수행하는 작업입니다. 따라서 호출에서 반환 된 결과의 날짜를 살펴보십시오. –