Can you do the below in WCF 4.0 Rest like you can in ASP.NET MVC?
In ASP.NET MVC I can create a strongly typed object commonly known as a ViewModel to handle error validation.
Instead of the following:
public ActionResult SomeAction(string firstname, string lastname, string address, int phone)
I could have the following:
public ActionResult SomeAction(UserObject obj)
Where UserObject is defined as:
public class UserObject
{
[Required(ErrorMessage = "firstname is a required paramater")]
public string firstname { get; set; }
[StringLength(50, ErrorMessage = "lastname is too long")]
public string lastname { get; set; }
[StringLength(160)]
public string address { get; set; }
public int phone { get; set; }
}
What I am basically wanting to do is create the parameters in a strongly typed object and have my error messages there. I could then format the error message as xml and return it to the user.
So in WCF REST. Instead of My method looking like:
[WebGet]
public IEnumerable<ObjectResult> SomeAction(string firstname, string lastname, string address, int phone)
I want the following:
[WebGet]
public IEnumerable<ObjectResult> SomeAction(UserObject obj)
Is this possible in WCF REST 4.0?