SAJ14SAJ
SAJ14SAJ

Reputation: 1708

ServiceStack: Raw Request Stream

I attempting to read the raw input stream in a ServiceStack Service. I have marked the DTO with IRequiresRequestStream, and the code to read executes, but the content always shows as blank.

Using debug mode in IE9, I can see the raw HttpRequest contains text within the POST as delivered.

Here is my code from a minimal test service intended only to show reading of the content and query:

[Route("/qtest")]
public class QueryTestRequest : IReturn<string>, IRequiresRequestStream
{
    public Stream RequestStream { get; set; }
}

public class QueryTestService : Service
{
    public string Any(QueryTestRequest request)
    {
        var r = new StringBuilder(); 
        r.Append("<p>This is the query test service:");

        r.AppendFormat("<p>Parameter value={0}", base.Request.QueryString["value"]);

        var postStream = new StreamReader(request.RequestStream);
        var postContent = postStream.ReadToEnd();           

        r.AppendFormat("<p>Raw Content={0}", postContent);

        return r.ToString();
    }
}

What am I missing here?

Upvotes: 1

Views: 1393

Answers (1)

Janus007
Janus007

Reputation: 366

Yes I find that weird as well, but maybe it's me who doesn't understand the nature of the HttpRequestStream.

Anyway... I managed to get hold of the file using:

var stream = Request.Files[0].InputStream;

And then you can handle that stream.

It appears that more than one file can be uploaded, but I guess that would be difficult to wrap into a REST-framework.

Upvotes: 1

Related Questions