forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHtmlServiceClient.cs
More file actions
60 lines (51 loc) · 1.83 KB
/
HtmlServiceClient.cs
File metadata and controls
60 lines (51 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.IO;
using ServiceStack.Web;
namespace ServiceStack.Common.Tests.ServiceClient.Web
{
public class HtmlServiceClient: ServiceClientBase
{
public HtmlServiceClient()
{
}
public HtmlServiceClient(string baseUri)
// Can't call SetBaseUri as that appends the format specific suffixes.
:base(baseUri, baseUri)
{
}
public override string Format
{
// Don't return a format as we are not using a ServiceStack format specific endpoint, but
// rather the general purpose endpoint (just like a html <form> POST would use).
get { return null; }
}
public override string Accept
{
get { return MimeTypes.Html; }
}
public override string ContentType
{
// Only used by the base class when POST-ing.
get { return MimeTypes.FormUrlEncoded; }
}
public override void SerializeToStream(IRequest requestContext, object request, Stream stream)
{
var queryString = QueryStringSerializer.SerializeToString(request);
stream.Write(queryString);
}
public override T DeserializeFromStream<T>(Stream stream)
{
return (T) DeserializeDtoFromHtml(typeof (T), stream);
}
public override StreamDeserializerDelegate StreamDeserializer
{
get { return DeserializeDtoFromHtml; }
}
private object DeserializeDtoFromHtml(Type type, Stream fromStream)
{
// TODO: No tests currently use the response, but this could be something that will come in handy later.
// It isn't trivial though, will have to parse the HTML content.
return Activator.CreateInstance(type);
}
}
}