I'm a bit confused with HttpResponseMessage and Task<HttpResponseMessage>.
If I'm using the HttpClient method PostAsync() to post data I need to give the Web Service method the Task<HttpResponseMessage> instead of HttpResponseMessage as return value as far as I understood things.
If I use Request.CreateResponse(HttpStatusCode.Forbidden, myError.ToString());
then I'm only getting the Response message object but not the Task object.
So my question here is how do I have to create the Fitting return for async calls to web api methods?
(thus are my understandings there correct and if so how to best transform the message object int a Task<HttpResponseMessage> object)
The original code:
public HttpResponseMessage DeviceLogin(MyDevice device)
{
EnummyError myError = EnummyError.None;
// Authenticate Device.
myError = this.Authenticate(device);
if (myError != EnummyError.None)
{
return Request.CreateResponse(HttpStatusCode.Forbidden, myError.ToString());
}
}
The updated Method header:
public Task<HttpResponseMessage> DeviceLogin(MyDevice device)