问题
I need make response compression disabled. I have .NET 4.5 version of web.config but I need in .NET CORE 2.x now.
<customBinding>
<binding name="BasicHttpBinding_Service">
<textMessageEncoding messageVersion="Soap11" />
<httpsTransport decompressionEnabled="false" />
</binding>
</customBinding>
I have web service which is not support compressed response and I am still get error: System.ServiceModel.ProtocolException: 'The content type application/x-gzip of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 653 bytes of the response were: '?'
Thank you very much
回答1:
ASP.NET Core has documentation on compression. As you can see, ASP.NET Core no longer uses web.config. If you're hosting your ASP.NET Core app in IIS, then some web.config settings are still used, but only those relevant to generic IIS hosting, nothing application specific (dynamic compression is an IIS feature, so that setting is still relevant, but other web.config settings that used to be relevent in ASP.NET apps are no longer used in ASP.NET Core). Unfortunately I can't find documentation at the moment as to which web.config settings are still relevant.
Anyway, ASP.NET Core by default uses the Kestrel web server, which is configured in code. Making a small modification to the sample in the documentation I linked above, I beleive this might work:
public void ConfigureServices(IServiceCollection services)
{
services.AddResponseCompression(options =>
{
var gzip = options.Providers.OfType<GzipCompressionProvider>().FirstOrDefault();
if (gzip != null)
{
options.Providers.Remove(gzip);
}
});
}
But it depends where the compression is coming from. If you have a reverse proxy between your ASP.NET Core app and the internet (for example IIS, but maybe nginx, haproxy, etc) they might be doing compression, so you need to understand your application architecture and turn it off at the right place.
来源:https://stackoverflow.com/questions/53559038/asp-net-core-disable-response-decompression