3
using ServiceStack.Service;
4
using ServiceStack.ServiceHost;
5
using ServiceStack.Text;
7
namespace ServiceStack.ServiceClient.Web
9
public class JsvRestClientAsync
12
public const string ContentType = "application/jsv";
14
public JsvRestClientAsync(string baseUri)
17
this.BaseUri = baseUri.WithTrailingSlash();
20
public JsvRestClientAsync()
22
this.client = new AsyncServiceClient {
23
ContentType = ContentType,
24
StreamSerializer = SerializeToStream,
25
StreamDeserializer = TypeSerializer.DeserializeFromStream
29
public TimeSpan? Timeout
31
get { return this.client.Timeout; }
32
set { this.client.Timeout = value; }
35
private static void SerializeToStream(IRequestContext requestContext, object dto, Stream stream)
37
TypeSerializer.SerializeToStream(dto, stream);
40
private readonly AsyncServiceClient client;
42
public string BaseUri { get; set; }
44
public void SetCredentials(string userName, string password)
46
this.client.SetCredentials(userName, password);
49
private string GetUrl(string relativeOrAbsoluteUrl)
51
return relativeOrAbsoluteUrl.StartsWith("http:")
52
|| relativeOrAbsoluteUrl.StartsWith("https:")
53
? relativeOrAbsoluteUrl
54
: this.BaseUri + relativeOrAbsoluteUrl;
57
public void GetAsync<TResponse>(string relativeOrAbsoluteUrl, Action<TResponse> onSuccess, Action<TResponse, Exception> onError)
59
this.client.SendAsync(HttpMethod.Get, GetUrl(relativeOrAbsoluteUrl), null, onSuccess, onError);
62
public void DeleteAsync<TResponse>(string relativeOrAbsoluteUrl, Action<TResponse> onSuccess, Action<TResponse, Exception> onError)
64
this.client.SendAsync(HttpMethod.Delete, GetUrl(relativeOrAbsoluteUrl), null, onSuccess, onError);
67
public void PostAsync<TResponse>(string relativeOrAbsoluteUrl, object request, Action<TResponse> onSuccess, Action<TResponse, Exception> onError)
69
this.client.SendAsync(HttpMethod.Post, GetUrl(relativeOrAbsoluteUrl), request, onSuccess, onError);
72
public void PutAsync<TResponse>(string relativeOrAbsoluteUrl, object request, Action<TResponse> onSuccess, Action<TResponse, Exception> onError)
74
this.client.SendAsync(HttpMethod.Put, GetUrl(relativeOrAbsoluteUrl), request, onSuccess, onError);
77
public void Dispose() {}
b'\\ No newline at end of file'