tags:

views:

13

answers:

1

I am using RestSharp in ASP .NET MVC 2 project. Trying to create RestRequest (using POST method) and add two enum values (my enum type -- OrderStatusFlags) to request body -- using build-in RestSharp XmlSerializer:

var request = new RestRequest("orders/{vendorID}/{number}", Method.POST);
request.AddBody(previousOrderStatus);
request.AddBody(newOrderStatus);

But after calling AddBody method in request parameters can see only empty but no value. And while calling MVC action method an error occurs:

The parameters dictionary contains a null entry for parameter 'previousStatus' of non-nullable type 'OrderStatusFlags' for method 'RestResponse PostOrderStatus(Int32, System.String, OrderStatusFlags, OrderStatusFlags)' in 'OrdersResourceEndpoint'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Parameter name: parameters

Enum look like this:

public enum OrderStatusFlags : long
{
    Pending,

    Confirmed,

... }

Does anybody occurs a similiar situation?

A: 

A couple issues here. First, you can only call AddBody() once or the last call will take precedence. AddBody() is also only for sending XML as the request body. What is the required XML schema that you need to send to that URL? Can you post some sample XML that you're trying to generate?

I think more likely you actually want to use AddParameter() to add some POST parameters since that is far more common than XML request bodies.

John Sheehan
Thank you very much for expand answer! You are quite right - it would better to use parameters for this task!
Polina