1

What is the appropriate way to request the HTML format of a DTO using ServiceClientBase?

I have tried the following:

string GetHtml(IReturn request) {
    var relativeUrl = request.ToUrl("GET", "html");
    return ServiceClient.Get<string>(relativeUrl);
}

However, the returned string is truncated at the first instance of =". For example, if I have a style tag, I'll only get the following response:

<!doctype html>
<html>
<head>
    <title>Report</title>
    <style type="

It seems the response is going through deserialization... How should I avoid this?

Rationale

There are two reasons I'd like to use the ServiceClient instance, rather than create an independent web request:

  1. The ServiceClient as the one-stop-shop for all web requests is easily mocked with fake or demo data. (This is convenient for testing or demonstrating the UI apart from a server instance.)
  2. Authentication credentials are supplied to the ServiceClient at once. It's undesirable for this concern to be repeated.

Finally, from an API perspective it would seem parallel to web services that can return a plain string, stream, etc. to have a client that can likewise get the "plain" result.

Community
  • 1
  • 1
Jacob Foshee
  • 2,704
  • 2
  • 29
  • 48

1 Answers1

2

Kind of not sure what you want to do. A HTML Response can't be serialized into a DTO so you shouldn't try using one of the Service Clients which are typed into handling a specific response that's serializable into a response DTO.

So to get the HTML response for a Service you can just use a basic HTTP Client like ServiceStack's HTTP Utils, e.g:

var url = BaseUrl + request.ToUrl("GET", "html");
var html = url.GetStringFromUrl();
mythz
  • 141,670
  • 29
  • 246
  • 390
  • Thanks, Demis, for your prompt response. I've updated the question with more info on why I'd like to use the ServiceClient if possible. That said, your answer is helpful in saving me from creating a WebRequest myself. I will read the docs to see how I might add basic auth. – Jacob Foshee Oct 29 '13 at 17:05