Good day,
I have created a client and self hosted service based on the Hello World sample. On the client I call the service as follows:
try
{
var client = new JsonServiceClient("http://127.0.0.1:1337/");
var request = new Hello
{
Name = @"vs2012I.iso"
};
Console.WriteLine("Connected.");
var response = client.PostFileWithRequest<HelloResponse>(new FileInfo(@"C:\Temp\vs2012I.iso"), request);
Console.WriteLine(response.Result);
}
catch (Exception e)
{
Console.WriteLine(e);
}
The service is implemented as follows:
public class HelloService : ServiceStack.Service
{
public HelloResponse Post(Hello request)
{
Console.WriteLine("Received request.");
if (Request.Files == null || Request.Files.Length != 1)
return new HelloResponse
{
Result = "No file was uploaded."
};
var httpFile = Request.Files[0];
var documentFile = Path.Combine(@"C:\Temp\SS Large", request.Name);
//httpFile.SaveTo(documentFile);
using (var fileStream = new FileStream(documentFile, FileMode.CreateNew))
{
httpFile.InputStream.CopyTo(fileStream);
}
Console.WriteLine("Request processed.");
return new HelloResponse { Result = "File uploaded: " + request.Name };
}
}
When uploading a file of around 1.2GB I get:
Exception of type ‘System.OutOfMemoryException’ was thrown.
at System.IO.MemoryStream.set_Capacity(Int32 value)\r\n at System.IO.MemoryStream.EnsureCapacity(Int32 value)\r\n at System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count)\r\n at System.IO.Stream.InternalCopyTo(Stream destination, Int32 bufferSize)\r\n at System.IO.Stream.CopyTo(Stream destination)\r\n at ServiceStack.Host.HttpListener.ListenerRequest.LoadMultiPart()\r\n at ServiceStack.Host.HttpListener.ListenerRequest.get_Form()\r\n at ServiceStack.Host.HttpListener.ListenerRequest.get_FormData()\r\n at ServiceStack.Host.Handlers.ServiceStackHandlerBase.DeserializeHttpRequest(Type operationType, IRequest httpReq, String contentType)\r\n at ServiceStack.Host.Handlers.GenericHandler.CreateRequest(IRequest req, String operationName)\r\n at ServiceStack.Host.Handlers.GenericHandler.ProcessRequestAsync(IRequest httpReq, IResponse httpRes, String operationName)
This happens with much smaller file (around 400mb) in my actual application (also self hosted).
I have tried hard to find the reason and/or solution for this but to no avail.
I’d appreciate some guidance.
Thanks.