2

hello world の例と自己ホスト型の例で ServiceStack を学習しようとしています。JSON コンテンツをリクエストしています。

応答ヘッダーで次のことに気付きました。

ASP.Net プロジェクトでホストされる基本的なサービス:

HTTP/1.1 200 OK
Server: ASP.NET Development Server/10.0.0.0
Date: Wed, 10 Apr 2013 12:49:46 GMT
X-AspNet-Version: 4.0.30319
X-Powered-By: ServiceStack/3.943 Win32NT/.NET
Cache-Control: private
Content-Type: application/json; charset=utf-8
Content-Length: 16   <-------------------------------------
Connection: Close

同じ基本サービス、セルフホスティング (コマンドライン):

HTTP/1.1 200 OK
Transfer-Encoding: chunked <-------------------------------
Content-Type: application/json; charset=utf-8
Server: Microsoft-HTTPAPI/2.0
X-Powered-By: ServiceStack/3.943 Win32NT/.NET
Date: Wed, 10 Apr 2013 12:48:50 GMT

自己ホスト型の品種は応答をバッファリングしないようですか? これはパフォーマンスまたは互換性の問題ですか?

セルフホスティング方式を使用している場合、バッファリングを有効にするにはどうすればよいですか?

どうもありがとう。

4

1 に答える 1

5

セルフホスティング方式を使用している場合、バッファリングを有効にするにはどうすればよいですか?

以下のような ResponseFilter を作成できます。これは一種の攻撃的であり、他の ResponseFilter の実行を妨げると思います。これをFilter Attributeに変換し、Response のパフォーマンスに明らかな利点がある場合にのみ使用できます。それ以外の場合は、AppHost に応答を処理させます。

ResponseFilters.Add((httpReq, httpRes, dto) =>
{
    using (var ms = new MemoryStream())
    {
        EndpointHost.ContentTypeFilter.SerializeToStream(
            new SerializationContext(httpReq.ResponseContentType), dto, ms);

        var bytes = ms.ToArray();

        var listenerResponse = (HttpListenerResponse)httpRes.OriginalResponse;
        listenerResponse.SendChunked = false;
        listenerResponse.ContentLength64 = bytes.Length;
        listenerResponse.OutputStream.Write(bytes, 0, bytes.Length);
        httpRes.EndServiceStackRequest();
    }
});
于 2013-04-12T15:07:41.150 に答える