5

I am returning HttpResult from one of the rest service methods using servicestack's new API. Is there a way to get the HttpResult using the JsonServiceClient?

For ex: JSonServiceClient.Send<HttpResult>("DELETE","person", new { PersonID = 30 });

I want to inspect the header information from the httpresult.

Thanks.

Tech Xie
  • 927
  • 4
  • 12
  • 24

1 Answers1

6

There's no such thing as a HttpResult client response from a ServiceStack web service.

You use a HttpResult to customize the HTTP Response that's returned from your service, e.g. Add additional HTTP Headers. But the response body the client sees is still only the Response DTO (if any).

Use fiddler, wireshark, chome web inspector (if this is an Ajax call) or something like ServiceStack's Request Logger plugin to inspect the HTTP traffic.

Invalid use of ServiceStack's REST Clients

Also consider using the appropriate Clients REST API like client.Delete(), client.Get() etc instead of overloading the T.Send() method (which is usually a POST).

Use Typed DTOs in the ServiceClient instead of anonymous types which are not supported.

Inspecting HTTP Headers using the ServiceStack Service Clients

ServiceStack's Service Clients provide Local and Global WebResponse (and Request) filters that you can use to introspect the WebClient's HttpWebResponse returned for that request, e.g:

client.ResponseFilter = httpRes => {
   httpRes.Headers.. //do something with returned headers
};
client.Delete(new Person { Id = 30, ...});
mythz
  • 141,670
  • 29
  • 246
  • 390
  • The http result looks good on fiddler which is what I use to test my services. Was curious if the servicestack client will be able to see the result. I wanted to inspect the header via code. Thanks! – Tech Xie Nov 08 '12 at 22:12
  • In that case, I've updated the answer to include an example of accessing the returned headers using the service clients. – mythz Nov 08 '12 at 22:42
  • In REST it is pretty common to do a Post request and have a response with 201 and Location header returned with no body. ServiceStack promotes avoiding HTTP. Am I right? – Kugel Jan 20 '13 at 07:01