I am quite new to ServiceStack, I am following the example at http://nilsnaegele.com/codeedge/servicestack1.html which I have been finding useful. I read that explicit StatusResponse fields in DTO Response declarations were not required in the new API, but I dont appear to be getting the expected behaviour here.
Using ServiceStack 3.9.71.
I introduced an Exception in the EntryService post to get a feel for the client handling.
public object Post(Entry request)
{
if (request.Quantity == 3)
{
throw new WebException("post entry");
}
}
With
public class EntryResponse
{
public int Id { get; set; }
}
Then in the client side when posting an Entry handle the exception.
try
{
var entryRequest = new Entry {Quantity = quantity, EntryTime = DateTime.Now};
var response = client.Send(entryRequest);
Console.WriteLine("Response: {0}", response.Id);
}
catch (WebServiceException wse)
{
// At this point wse.ResponseStatus field is null.
}
I tested out explicitly adding the ResponseStatus field to EntryResponse and this produced the ResponseStatus filled in on the client with no change to the client code.
I then tried throwing an exception in StatusRequestService as follows to see if the second web service client request would behave the same way, and it appears it behaves differently.
public object Any(StatusRequest request)
{
if (request.Lever == 3)
{
throw new WebException("get status.");
}
}
With the following.
public class StatusResponse
{
public int Total { get; set; }
public int Goal { get; set; }
}
Then catching this in the client as per
try
{
var postResponse = client.Post<StatusResponse>("status", new StatusRequest { Date = DateTime.Now, Lever = 3 });
Console.WriteLine("{0} of {1} achieved", postResponse.Total, postResponse.Goal);
}
catch (WebServiceException wse)
{
// At this point wse.ResponseStatus field is valid and filled in.
}