【问题标题】:Getting null after passing Content-Type json raw in body在正文中传递 Content-Type json raw 后获取 null
【发布时间】:2018-05-22 10:54:24
【问题描述】:

服务就像

    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
        };
    }

当我尝试从邮递员运行服务时,一个变量的输出为空

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 也被其他继承

我发送的 Content-Type 是 application/json

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

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

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

【问题讨论】:

  • 您的代码使用了ForGotModel,但您只显示了StoreForGotModel。你有不同的ForGotModel 类吗?
  • 对不起。我忘记在这个代码spinet中删除。我使用的是相同的型号。

标签: c# json wcf


【解决方案1】:

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

public class ForgotResult
{

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

【讨论】:

    猜你喜欢
    • 2011-08-11
    • 2015-08-30
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    • 2013-01-07
    • 1970-01-01
    • 2012-06-15
    相关资源
    最近更新 更多