WebApi 2返回null结果

时间:2015-12-14 13:12:11

标签: c# asp.net-web-api asp.net-web-api2

我有一个简单的WebApi动作,它应该以json格式返回一个复杂的类型。不幸的是,我唯一得到的是

{"Message":null}

我想要回归的对象并不特别。它基本上适用于没有任何注释的此表单:

enum A
{
    A,
    B,
    C
}

class B
{
    public bool PropertyA { get; set; }
    public int PropertyB { get; set; }
    public string PropertyC { get; set; }
    public A PropertyEnum { get; set; }
}

class C
{
    public bool PropertyA { get; set; }
    public int PropertyB { get; set; }
    public string PropertyC { get; set; }
    public B PropertyClassB { get; set; }
}

我从遗留数据库抽象中获取了正确的对象。

现在我返回这样的对象:

public IHttpActionResult GetInstanceOfC([FromBody]SomeObject arg)
{
    try
    {
        // Legacy stuff that constructed the object
        return Ok(data);
    }
    catch(/* ... */)
    {
        /* ... */
    }
}

我从Api得到的是这个,虽然Response对象看起来是正确的:

{"Message":null}

我停用了XMLMediaTypeFormatter和模型绑定验证。

0 个答案:

没有答案
相关问题