我意识到 Web API 以 REST 为中心,但我仍然想配置一个可以处理命令/响应场景的控制器方法。到目前为止,我还没有成功......有没有办法让单个 API 端点识别以下类结构?
[Serializable]
public abstract class Command{
public int CommandId{get; set;}
}
[Serializable]
public class RegisterNewPersonCommand:Command{
public string Name{get; set;}
}
//etc... various Command subclasses. Similar thing for Responses.
//now have a single endpoint to Handle Commands
public class CommandsController : ApiController{
public Response HandleCommand(Command command){
//handle Command based on which subclass it is
//return appropriate Response subclass
}
}
到目前为止,序列化系统似乎无法处理这种情况,但我希望有人找到一种方法来做到这一点:)