在正文中传递Content-Type json raw后获取null

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在正文中传递Content-Type json raw后获取null相关的知识,希望对你有一定的参考价值。

服务就像

    public ServiceResult<ForGotModel> ForGotPassword(ForGotModel model)
    {

            int errorState = 0, errorSeverity = 0;
            string message = string.Empty;
    // other works goes here

    return new ServiceResult<ForGotModel>()
        {
            ErrorState = errorState,
            ErrorSeverity = errorSeverity,
            Message = message
        };
    }

当我尝试从postman运行服务时,一个变量的输出为null

public class ForgotResult
{

    [Required]
    [Display(Name = "User Name")]
    public string UserName { get; set; }
}
public class ForGotModel : ForgotResult
{

    [Display(Name = "Store Code")]
    [DataMember]
    public string StoreCode { get; set; }
}

[OperationContract]
     [WebInvoke(Method = "POST",
     UriTemplate = "/StoreForGotPassword",
       RequestFormat = WebMessageFormat.Json,
     ResponseFormat = WebMessageFormat.Json)]
     ServiceResult<ForGotModel> 
     ForGotPassword(ForGotModel model);

ForgotResult也在其他地方继承

我发送的内容类型是application / json

{
"StoreCode":"44YLS1001",
"UserName":"vbn"
}

但是对于StoreCode,我得到了值,对于UserName,我得到了null

任何可以帮助我的建议?cca提前感谢。

答案

我得到了解决方案。刚刚[DataMember]更新

public class ForgotResult
{

[Required]
[DataMember]
[Display(Name = "User Name")]
public string UserName { get; set; }
}

以上是关于在正文中传递Content-Type json raw后获取null的主要内容,如果未能解决你的问题,请参考以下文章