1 using System; 2 using System.IO; 3 using ServiceStack.ServiceHost; 4 using ServiceStack.ServiceModel.Serialization; 5 using ServiceStack.Text; 6 7 namespace ServiceStack.ServiceClient.Web 8 { 9 public class JsonServiceClient 10 : ServiceClientBase 11 { 12 public override string Format 13 { 14 get { return "json"; } 15 } 16 JsonServiceClient()17 public JsonServiceClient() 18 { 19 } 20 JsonServiceClient(string baseUri)21 public JsonServiceClient(string baseUri) 22 { 23 SetBaseUri(baseUri); 24 } 25 JsonServiceClient(string syncReplyBaseUri, string asyncOneWayBaseUri)26 public JsonServiceClient(string syncReplyBaseUri, string asyncOneWayBaseUri) 27 : base(syncReplyBaseUri, asyncOneWayBaseUri) 28 { 29 } 30 31 public override string ContentType 32 { 33 get { return String.Format("application/{0}", Format); } 34 } 35 SerializeToStream(IRequestContext requestContext, object request, Stream stream)36 public override void SerializeToStream(IRequestContext requestContext, object request, Stream stream) 37 { 38 JsonDataContractSerializer.Instance.SerializeToStream(request, stream); 39 } 40 DeserializeFromStream(Stream stream)41 public override T DeserializeFromStream<T>(Stream stream) 42 { 43 return JsonDataContractDeserializer.Instance.DeserializeFromStream<T>(stream); 44 } 45 46 public override StreamDeserializerDelegate StreamDeserializer 47 { 48 get { return JsonSerializer.DeserializeFromStream; } 49 } 50 } 51 }