I've been doing a lot of research trying to find the best way to communicate a mass assignment POST request with my ASP.NET MVC3 app without much success.


Here's the scenario:
Like I mentioned, I have a ASP.NET MVC3 with standard REST methods, with which I'm trying to communicate with a desktop application (another app written in-house). To start with as a prototype, we just used the brute force XML document upload through WebClient and then having the MVC3 application parse through the XML document. In order to maintain this behavior we would have to be constantly building multiple methods, one for the XML document parsing, and one for standard model usage on the website. I'd like to stay away from that if I can.


After all my research I came across RestSharp and I'm wondering if there is someway to handle mass assignment POST requests using RestSharp. I'd like to be able to do something like the following:

In the MVC3 app...

public class RegistrationRequest {
    public string Email { get; set; }
    public string RequestedUserName { get; set; }

    public bool Register(string domain) {
        // Do registration stuff.
    }
}

public class AccountController : Controller {
    [Authorize,HttpPost]
    public ActionResult Register(IEnumerable<RegistrationModel> models) {
        return models.Any(model => !model.Register(this.Url.DnsSafeHost))
                   ? new HttpStatusCodeResult(400)
                   : new HttpStatusCodeResult(200);
    }
}

In the desktop app...

public class RegistrationRequest {
    public string Email { get; set; }
    public string RequestedUserName { get; set; }
}

public class RegistrationService {
    public void CreateUsers() {
        List<RegistrationRequest> registrations = new List<RegistrationRequest>();
        // list of requested users built up by app

        var client = new RestClient(baseUrl);
        var request = new RestRequest("Account/Register", Method.POST);
        //request.AddAllMyObjects(registrations);
        var response = client.Execute(request);
    }
}

Can anyone give me any pointers on how to achieve this?

有帮助吗?

解决方案

After looking through the docs and a quick back and forth with John Sheenan, I found that this is not currently possible. I ended up making singular requests to the API we developed. Since this runs in the background, it doesn't really affect the user experience on the desktop app and the requests were must smaller and more succinct anyways.

I found that this actually enabled us to get better results anyways on each individual pass/fail case and handle those appropriately. While it might have been nice, this "one at a time" request actually proved to be better in the end.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top