Breeze の の設定に問題がありますJsonMediaTypeFormatter
。私がすることは、WebAPI によって送受信される json の日付が常に UTC で機能することです。
このドキュメントによると、プロパティDateTimeZoneHandling
をDateTimeZoneHandling.Utc
に設定することで可能になりますJsonSerializerSettings
しかし、それはうまくいきませんでした。
このソース コードを調べたところ、この動作に影響を与えている可能性があるのは、この別の問題に対して行われたハッキングであることがわかりました。
以下のコードをすべて削除すると、すべて正常に動作します。
//jsonSerializerSettings.Converters.Add(new IsoDateTimeConverter
//{
// DateTimeFormat = "yyyy-MM-dd\\THH:mm:ss.fffK"
//});
ハックを削除せずにこの状況に対処するにはどうすればよいですか?
編集1
私の最初の設定の試みは次のとおりです。
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 ではありませんでした。
編集2
まず、Breeze lib を 0.80.3 バージョンに更新しました。
私の 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());
}
}
}
次に、BreezeConfig という名前のフォルダーに CustomBreezeConfig.cs クラスを作成しました (Jay が以下に説明するコードを使用)。しかし、この新しい試みは機能しませんでした。
よろしく、
ベルナルド・パチェコ