私は非常に単純な NancyFX モジュールを持っています。これは、単に API 呼び出しの結果を送信者にエコーしたいだけです。
受信 XML を JSON に変換してから Nancy エンドポイントに渡すファサードを使用しています。このファサードは、API のエコー サービスを使用してテストし、応答を確認できるため、コンテンツを JSON に正しく変更します。
ただし、ファサードは content-length ヘッダーを削除し、transfer-encoding をチャンクに設定するため、Nancy モジュールの Request.Body は常に空です。
NancyFX で Chunked エンコーディングのサポートを有効にするために必要な構成はありますか?
現在 IIS 7 でホストしていますが、IIS 8 にもアクセスできます。
OWIN ホスティングを使用すると、HostConfiguration を使用してチャンク転送を有効にできることがわかりますが、他の要因により、OWIN ホスティングを使用できず、IIS ホスティングに依存することができません。
次のコマンドを使用して、IIS でチャンク転送を有効にしました。
appcmd set config /section:asp /enableChunkedEncoding:True
私のweb.configは現在:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5.1" />
<httpHandlers>
<add verb="*" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" path="*" />
</httpHandlers>
<httpRuntime targetFramework="4.5.1" />
<webServices>
<protocols>
<add name="HttpGet" />
<add name="HttpPost" />
</protocols>
</webServices>
</system.web>
<system.webServer>
<modules>
<remove name="WebDavModule" />
</modules>
<handlers>
<remove name="WebDAV" />
<add name="Nancy" verb="*" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" path="*" />
</handlers>
<validation validateIntegratedModeConfiguration="false" />
<httpErrors existingResponse="PassThrough" />
</system.webServer>
</configuration>
モジュール自体は非常にシンプルで、次のもので構成されています。
Post["/"] = parameters =>
{
var traceRef = Guid.NewGuid();
var body = this.Request.Body.AsString();
Logger.Trace("Trace ref: {0}, request inbound.", traceRef);
Logger.Trace(body);
AuthRequest auth = new AuthRequest();
try
{
auth = this.Bind<AuthRequest>();
}
catch (Exception ex)
{
Logger.Error("Trace ref: {0}, error: {1}. Exception: {2}", traceRef, ex.Message, ex);
}
var responseObject = new
{
this.Request.Headers,
this.Request.Query,
this.Request.Form,
this.Request.Method,
this.Request.Url,
this.Request.Path,
auth
};
return Response.AsJson(responseObject);
};