My question is basically if RestSharp has problems with primitive types returned by web api?
Here's how I am consuming a ASP.net web api:
public T Execute<T>(RestRequest request) where T : new()
{
var response = _client.Execute<T>(request);
if(response.ResponseStatus != ResponseStatus.Completed)
{
throw response.ErrorException;
}
return response.Data;
}
The ASP.net Web api has an action:
[HttpPost]
public bool Login(UserAccount account)
{
return true;
}
When I call this web service fiddler, I see this:
Date: Mon, 27 Aug 2012 13:19:10 GMT
X-AspNet-Version: 4.0.30319
Content-Type: application/json; charset=utf-8
Incidentally, the JSON tab in the Fiddler Response window, has nothing. Does this mean, this response is not well formed JSON?
When this action is called, RestSharp throws an exception:
"Message": "An error has occurred.",
"ExceptionMessage": "Unable to cast object of type 'System.Boolean' to type 'System.Collections.Generic.IDictionary`2[System.String,System.Object]'.",
"ExceptionType": "System.InvalidCastException",
at ServiceManager.Execute[T](RestRequest request) in ServiceManager.cs:line 92
at ServiceManager.Login(UserAccount userAccount) in ServiceManager.cs:line 78
at Login(UserAccount account) in AccountController.cs:line 30
at lambda_method(Closure , Object , Object[] )
at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass13.<GetExecutor>b__c(Object instance, Object[] methodParameters)
at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)
at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.<>c__DisplayClass5.<ExecuteAsync>b__4()
at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken)"
There's more. It seems like the deserializer is choking:
at RestSharp.Deserializers.JsonDeserializer.FindRoot(String content)
at RestSharp.Deserializers.JsonDeserializer.Deserialize[T](IRestResponse response)\r\n at RestSharp.RestClient.Deserialize[T](IRestRequest request, IRestResponse raw)
Any ideas?
Many thanks!