Hi, there. I'm evaluating ServiceStack right now. I like it very much and appreciate its opinionated nature. I have a few questions, however.
I'm trying to create a simple service to store and retrieve binary resources. My resource DTO looks like this:
public class Resource : IRequiresRequestStream
{
public Guid ResourceID { get; set; }
public string ContentType { get; set; }
public DateTime? ExpirationDate { get; set; }
public Stream Data { get; set; }
public Stream RequestStream
{
get { return Data; }
set { Data = value; }
}
}
var id = Guid.NewGuid();
var client = new JsonRestClientAsync(baseUri);
var filestream = File.OpenRead("C:\\Temp\\ResourcesTest\\client\\2048401invoice.pdf");
var resource = new Resource
{
ContentType = "application/pdf",
Data = filestream,
ResourceID = id
};
client.PutAsync<Resource>(relativeOrAbsoluteUrl: string.Format("/resource/{0}", id.ToString("N")),
onSuccess: response => Console.WriteLine("Success"),
onError: (response, ex) => Console.WriteLine(ex.ToString()),
request: resource);
}
And I'm getting this error: "Timeouts are not supported on this stream." (I'll copy the callstack and details at the bottom of this message). Does anyone know why? It seems to be originating from the client? It's trying to serialize my stream, it seems. Do I even want it to do that?
On a related note, what is the recommended way to deal with the fact that the client (I'm using the C# client) needs the same DTOs as the server? Is it advisable to use a common assembly, or have the DTOs defined separately?
Thanks! See the error below.
System.InvalidOperationException: Timeouts are not supported on this stream.
at System.IO.Stream.get_ReadTimeout()
at lambda_method(Closure , Stream )
at ServiceStack.Text.Common.WriteType`2.WriteProperties(TextWriter writer, Ob
ject value) in C:\src\ServiceStack.Text\src\ServiceStack.Text\Common\WriteType.c
s:line 201
at ServiceStack.Text.Common.WriteType`2.WriteAbstractProperties(TextWriter wr
iter, Object value) in C:\src\ServiceStack.Text\src\ServiceStack.Text\Common\Wri
teType.cs:line 178
at ServiceStack.Text.Common.WriteType`2.WriteProperties(TextWriter writer, Ob
ject value) in C:\src\ServiceStack.Text\src\ServiceStack.Text\Common\WriteType.c
s:line 216
at ServiceStack.Text.JsonSerializer.SerializeToStream(Object value, Type type
, Stream stream) in C:\src\ServiceStack.Text\src\ServiceStack.Text\JsonSerialize
r.cs:line 148
at ServiceStack.Text.JsonSerializer.SerializeToStream[T](T value, Stream stre
am) in C:\src\ServiceStack.Text\src\ServiceStack.Text\JsonSerializer.cs:line 135
at ServiceStack.ServiceClient.Web.JsonRestClientAsync.SerializeToStream(IRequ
estContext requestContext, Object dto, Stream stream) in C:\src\ServiceStack\src
\ServiceStack.Common\ServiceClient.Web\JsonRestClientAsync.cs:line 38
at ServiceStack.ServiceClient.Web.AsyncServiceClient.RequestCallback[T](IAsyn
cResult asyncResult) in C:\src\ServiceStack\src\ServiceStack.Common\ServiceClien
t.Web\AsyncServiceClient.cs:line 285