为了账号安全,请及时绑定邮箱和手机立即绑定

非异步调用异步方法时出错

非异步调用异步方法时出错

C#
杨__羊羊 2021-07-06 13:00:00
我有以下异步方法:[HttpGet][Route("api/SecurityRoles/AllowDeleteRole/{securityRoleId}")]public async Task<IHttpActionResult> AllowDeleteRole(int securityRoleId){    _systemLogger.LogInfo($"Method api/SecurityRoles/AllowDeleteRole (Get) called with securityRoleId: {securityRoleId}");    var securityRolePermission =            await _securityRolePermissionService.SecurityRolePermissionsCountBySecurityRoleId(securityRoleId);    if (securityRolePermission != SecurityRoleDeleteResult.Success) return Ok(SecurityRoleDeleteResult.RolePermissionExists);    var securityRolePageEntity =            await  _securityRolePageEntityService.SecurityRolePageEntityCountBySecurityRoleId(securityRoleId);    return Ok(securityRolePageEntity != SecurityRoleDeleteResult.Success ? SecurityRoleDeleteResult.RolePageEntityExists : SecurityRoleDeleteResult.Success);    }它在很多地方使用,但对于这个实例,我需要非异步地使用它,所以我有以下代码首先包装它:public async Task<SecurityRoleDeleteResult> AllowDeleteRole(int securityRoleId)    {        string url = $"{_housingDataSecurityConfiguration.HousingDataSecurityWebApiUrl}SecurityRoles/AllowDeleteRole/{securityRoleId}";        var message =  _apiClientService.Retrieve<HttpResponseMessage>(url);        if (message.StatusCode == HttpStatusCode.InternalServerError)        {            return SecurityRoleDeleteResult.ErrorOccurred;        }        int intResult = 0;        var apiResult = await message.Content.ReadAsStringAsync();        if (int.TryParse(apiResult, out intResult))        {            return (SecurityRoleDeleteResult)intResult;        }        else        {            return SecurityRoleDeleteResult.ErrorOccurred;        }    }我的问题是,当我尝试EnableDeleteButton = enableButton在模型中进行设置时,它会在线上抛出以下错误:enableButton = (result.Result == SecurityRoleDeleteResult.Success) ? true : false;{"将值 3 转换为类型 'System.Net.Http.HttpResponseMessage' 时出错。路径 '',第 1 行,位置 1。"}3 指的是我的 SecurityRoleDeleteResult 枚举上的枚举值之一。
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 153 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信