using System; using System.IO; using System.Threading; using ServiceStack.Common.Web; using ServiceStack.Service; using ServiceStack.ServiceHost; using ServiceStack.Text; namespace ServiceStack.ServiceClient.Web { [Obsolete("Use JsonServiceClient")] public class JsonRestClientAsync : IRestClientAsync { public const string ContentType = "application/json"; public JsonRestClientAsync(string baseUri) : this() { this.BaseUri = baseUri.WithTrailingSlash(); } public JsonRestClientAsync() { this.client = new AsyncServiceClient { ContentType = ContentType, StreamSerializer = SerializeToStream, StreamDeserializer = JsonSerializer.DeserializeFromStream }; } public TimeSpan? Timeout { get { return this.client.Timeout; } set { this.client.Timeout = value; } } private static void SerializeToStream(IRequestContext requestContext, object dto, Stream stream) { JsonSerializer.SerializeToStream(dto, stream); } private readonly AsyncServiceClient client; public string BaseUri { get; set; } public void SetCredentials(string userName, string password) { this.client.SetCredentials(userName, password); } public void GetAsync(IReturn request, Action onSuccess, Action onError) { throw new NotImplementedException(); } private string GetUrl(string relativeOrAbsoluteUrl) { return relativeOrAbsoluteUrl.StartsWith("http:") || relativeOrAbsoluteUrl.StartsWith("https:") ? relativeOrAbsoluteUrl : this.BaseUri + relativeOrAbsoluteUrl; } public void GetAsync(string relativeOrAbsoluteUrl, Action onSuccess, Action onError) { this.client.SendAsync(HttpMethods.Get, GetUrl(relativeOrAbsoluteUrl), null, onSuccess, onError); } public void DeleteAsync(string relativeOrAbsoluteUrl, Action onSuccess, Action onError) { this.client.SendAsync(HttpMethods.Delete, GetUrl(relativeOrAbsoluteUrl), null, onSuccess, onError); } public void DeleteAsync(IReturn request, Action onSuccess, Action onError) { throw new NotImplementedException(); } public void PostAsync(IReturn request, Action onSuccess, Action onError) { throw new NotImplementedException(); } public void PostAsync(string relativeOrAbsoluteUrl, object request, Action onSuccess, Action onError) { this.client.SendAsync(HttpMethods.Post, GetUrl(relativeOrAbsoluteUrl), request, onSuccess, onError); } public void PutAsync(IReturn request, Action onSuccess, Action onError) { throw new NotImplementedException(); } public void PutAsync(string relativeOrAbsoluteUrl, object request, Action onSuccess, Action onError) { this.client.SendAsync(HttpMethods.Put, GetUrl(relativeOrAbsoluteUrl), request, onSuccess, onError); } public void CustomMethodAsync(string httpVerb, IReturn request, Action onSuccess, Action onError) { throw new NotImplementedException(); } public void CancelAsync() { throw new NotImplementedException(); } public void Dispose() { } } }