When inheriting from the ServiceStack service's built-in service , you can access the basic request and response directly from the Response class with:
public class MyService : Service { public object Get(Request request) { base.Request ... base.Response ... } }
You will not see the answer in your service or filters, since it is directly recorded in the response stream and is the last thing that ServiceStack does after execution of your service and all response filters .
For HTTP diagnostics, I recommend using Fiddler or the WebInspector also built into ServiceStack ServiceStack may also help.
Using ServiceStack
If you use C # Service Clients , you can just ask what you want, for example. you can access the returned answer as a raw string:
string responseJson = client.Get<string>("/poco/World");
Or as raw bytes:
byte[] responseBytes = client.Get<byte[]>("/poco/World");
Or as a stream:
using (Stream responseStream = client.Get<Stream>("/poco/World")) { var dto = responseStream.ReadFully().FromUtf8Bytes().FromJson<PocoResponse>(); }
Or even access the populated HttpWebResponse object:
HttpWebResponse webResponse = client.Get<HttpWebResponse>("/poco/World"); webResponse.Headers["X-Response"] //World using (webResponse) using (var stream = webResponse.GetResponseStream()) using (var sr = new StreamReader(stream)) { string response = sr.ReadToEnd(); }
You can also explore HttpWebResponse using Global and Local Response filters, for example:
JsonServiceClient.HttpWebResponseFilter = httpRes => { .. };
Or using a local filter:
var client = new JsonServiceClient(baseUrl) { ResponseFilter = httpRes => { .. } };
Third party service consumption
If you are using a third-party REST / HTTP API, you can use responseFilter: in the ServiceStack HTTP Util extensions :
List<GithubRepo> repos = "https://api.github.com/users/{0}/repos".Fmt(user) .GetJsonFromUrl(responseFilter: httpRes => { var remaining = httpRes.Headers["X-Api-Remaining"]; }) .FromJson<List<GithubRepo>>();