我们在 DocumentDB 上有以ISO 8601 格式存储日期的文档。这些日期存储为字符串:
{
"CreatedOn": "2016-04-15T14:54:40Z",
"Title": "Some title",
"id": "xxx-xxx-xxxx-xxx-xxx-xxx"
}
Run Code Online (Sandbox Code Playgroud)
我们在使用 ASP.NET Core 的 WebAPI上使用最新的Azure DocumentDB SDK (1.7.0) 。
映射文档的 C# 类具有字符串形式的“CreatedOn”属性。
public class Item
{
public string CreatedOn { get; set; }
public string id { get; set; }
public string Title { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
问题是,当我们读取文档并且 SDK 对其进行反序列化时,它会尝试将其转换为DateTime,然后再转换回string。导致:
{
"CreatedOn": "15/04/2016 14:54:40",
"Title": "Some title",
"id": "xxx-xxx-xxxx-xxx-xxx-xxx"
}
Run Code Online (Sandbox Code Playgroud)
我需要的是 SDK 保持这些值不变。我尝试设置默认的 …
我正在研究使用以下堆栈的SignalR Core Web应用程序:
客户端使用SignalR NPM包(@ aspnet/signalr).
该应用程序配置如下:
public void ConfigureServices(IServiceCollection services)
{
services.AddCors(options =>
{
options.AddPolicy(
"CorsPolicy",
builder => builder
.AllowCredentials()
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader());
});
services.AddSignalR();
}
public void Configure(IApplicationBuilder app)
{
app.UseCors("CorsPolicy");
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseWebSockets();
app.UseSignalR(routes =>
{
routes.MapHub<ClientHub>("/hubs/notifications");
});
}
Run Code Online (Sandbox Code Playgroud)
在本地运行时http://localhost
,客户端使用WS协议进行连接.但是,当部署在Azure App Service中时,它会回退到SSE.
浏览器日志显示:
WebSocket connection to 'wss://xxxxxx.azurewebsites.net/hubs/notifications?id=ZRniWKpMLMPIyLhS5RSyAg' failed: Error during WebSocket handshake: Unexpected response code: 503
Information: SSE connected to https://xxxxxx.azurewebsites.net/hubs/notifications?id=ig47oOdQzbasdgrlr0cHaw
Run Code Online (Sandbox Code Playgroud)
该negotiate
方法似乎返回对Websockets的支持:
{"connectionId":"ZRniWKpMLMPIyLhS5RSyAg",
"availableTransports":[
{"transport":"WebSockets","transferFormats":["Text","Binary"]}, …
Run Code Online (Sandbox Code Playgroud) c# websocket azure-web-sites asp.net-core asp.net-core-signalr