问题描述
让我用代码解释一下。
[HttpGet]
public async Task<IActionResult> GetTasks(Guid propertyId,[FromQuery] TaskFilterParams filterParams,[FromQuery] SortingParams sortingParams,[FromQuery] PagingParams pagingParams)
{
// Do some stuff,not important
}
因此我们使用以下网址调用此端点:someurl.com/api/v1/properties/[some-guid]/tasks?&roomClass=Single&category=Cleaning 如您所见,我们只提供了三个值:GUID、房间类型和任务类别。排序和分页参数为空。 问题是'category'参数没有填写,一直为null,而其他参数填写正确。无论我们尝试什么(url编码,重新排列参数的顺序,......)。 然而,真正的问题是,如果我们重新启动服务,它有时会工作一段时间。但每隔一段时间它就会失败,我们需要再次重新启动一切。
PS:代码在 AKS 的 docker 容器中运行(来自 mcr.microsoft.com/dotnet/core/aspnet:3.1)。
[DBG] Get tasks parameters: PropertyId: [some-guid],TaskFilterParams:{"Category": null,"RoomClass": {"Value": "Single","Operator": "Equal","$type": "FilterParam`1"},"$type": "TaskFilterParams"}
public class TaskFilterParams
{
public FilterParam<IssueCategory> Category { get; set; }
public FilterParam<RoomClass> RoomClass { get; set; }
public FilterParam<Guid?> Room { get; set; }
}
public abstract class FilterParam
{
public FilterOperator Operator { get; set; }
}
[TypeDescriptionProvider(typeof(FilterParamTypeDescriptionProvider))]
[JsonObject]
public class FilterParam<T> : FilterParam
{
public T Value { get; set; }
public static bool TryParse(string s,out FilterParam<T> result)
{
result = default(FilterParam<T>);
var filterOperators = Enum.GetValues(typeof(FilterOperator)).Cast<FilterOperator>();
foreach (var filterOperatorString in filterOperators.Select<FilterOperator,string>(x => x.ToFilterOperatorString()).OrderByDescending(x => x.Length))
{
if (s.StartsWith(filterOperatorString))
{
if (s.TryParse(filterOperatorString,out result))
{
return true;
}
return false;
}
}
return false;
}
}
public enum IssueCategory
{
Cleaning = 0,inspection = 1,Maintenance = 2
}
public enum RoomClass
{
Single = 0,Double = 1,Family = 2
}
更新: 我们添加了更多日志记录。查询字符串中似乎存在数据,但模型未正确绑定。
Log.Debug("Query: {@query}",HttpContext.Request.Query);
Log.Debug(
"Get tasks parameters: PropertyId:{@propertyId},TaskFilterParams:{@filterParams},SortingParams:{@sortingParams},PagingParams:{@pagingParams}",propertyId,filterParams,sortingParams,pagingParams);
[16:51:35 DBG] Query: [{"Key": "category","Value": ["Cleaning"],"$type": "keyvaluePair`2"},{"Key": "roomClass","Value": ["Single"],"$type": "keyvaluePair`2"}]
[16:51:35 DBG] Get tasks parameters: PropertyId:[some-guid],"$type": "TaskFilterParams"}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)