gpt4 book ai didi

WCF 413 请求实体太大 - 自托管 WebHttpBinding

转载 作者:行者123 更新时间:2023-12-02 07:50:49 24 4
gpt4 key购买 nike

关于这个问题有很多讨论,但是我现在已经尝试了所有可能的解决方案,但我们仍然从服务器收到 413 Request Entity Too Large 错误。

我们的 WCF 服务是通过 Azure Worker 角色自行托管的,并且不使用 IIS。我们所有的配置都在代码中指定:

var host = new ServiceHost(searchEngine);

// Create binding
var binding = new WebHttpBinding(WebHttpSecurityMode.Transport);

binding.MaxReceivedMessageSize = 2147483647;
binding.MaxBufferSize = 2147483647;
binding.MaxBufferPoolSize = 2147483647;

var readerQuotas = new XmlDictionaryReaderQuotas
{
MaxStringContentLength = 2147483647,
MaxArrayLength = 2147483647,
MaxBytesPerRead = 2147483647,
MaxDepth = 2147483647,
MaxNameTableCharCount = 2147483647
};

// Setting quotas on a BindingElement after the binding is created has no effect on that binding.
// See: https://stackoverflow.com/questions/969479/modify-endpoint-readerquotas-programatically
binding.GetType().GetProperty("ReaderQuotas").SetValue(binding, readerQuotas, null);

binding.ReceiveTimeout = new TimeSpan(1, 0, 0);
binding.SendTimeout = new TimeSpan(1, 0, 0);

// Add the service endpoint
var ep = host.AddServiceEndpoint(
typeof(ISearchEngine),
binding,
string.Format("https://{0}/SearchEngine", externalEndpoint));

ep.Behaviors.Add(new WebHttpBehavior());

// Increase the MaxItemsInObjectGraph quota for all operations in this service
foreach (var operation in ep.Contract.Operations)
{
operation.Behaviors.Find<DataContractSerializerOperationBehavior>().MaxItemsInObjectGraph = 10000000;
}

return host;

这是我们的客户端配置 - 也在代码中指定:

var binding = new WebHttpBinding(WebHttpSecurityMode.Transport);

binding.MaxReceivedMessageSize = 2147483647;
binding.MaxBufferSize = 2147483647;
binding.MaxBufferPoolSize = 2147483647;

var readerQuotas = new XmlDictionaryReaderQuotas
{
MaxStringContentLength = 2147483647,
MaxArrayLength = 2147483647,
MaxBytesPerRead = 2147483647,
MaxDepth = 2147483647,
MaxNameTableCharCount = 2147483647
};

// Setting quotas on a BindingElement after the binding is created has no effect on that binding.
// See: https://stackoverflow.com/questions/969479/modify-endpoint-readerquotas-programatically
binding.GetType().GetProperty("ReaderQuotas").SetValue(binding, readerQuotas, null);

binding.ReceiveTimeout = new TimeSpan(1, 0, 0);
binding.SendTimeout = new TimeSpan(1, 0, 0);

binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;

var channelFactory = new ChannelFactory<ISearchEngine>(binding, endpointAddress);

channelFactory.Endpoint.Behaviors.Add(new WebHttpBehavior());


// Increase the MaxItemsInObjectGraph quota for all operations in this service
foreach (var operation in channelFactory.Endpoint.Contract.Operations)
{
operation.Behaviors.Find<DataContractSerializerOperationBehavior>().MaxItemsInObjectGraph = 10000000;
}

return channelFactory.CreateChannel();

我唯一的预感可能是 SSL 连接有问题?有一些文章提到了 IIS 特有的问题,但我不确定这是否与自托管服务相关。

非常感谢任何建议。

更新:

为了证实我的预感,SSL 是问题所在,我暂时禁用了 SSL,结果发现问题消失了。

所以现在我需要弄清楚为什么 SSL 会导致问题。有大量关于类似问题的文档,但它仅与 IIS 托管服务相关(我们的服务是从 Windows 服务自托管的):

IIS7 - (413) Request Entity Too Large | uploadReadAheadSize

有人知道仅适用于自托管 WCF 服务的等效设置吗?

最佳答案

由于这篇看似无关的帖子,我发现了问题:

http://forums.newatlanta.com/messages.cfm?threadid=554611A2-E03F-43DB-92F996F4B6222BC0&#top

这绝对是 SSL 问题,与将 SSL 证书绑定(bind)到您托管的端口有关。您必须使用 netsh 绑定(bind)证书并将 clientcertnegotiation=enable 添加到绑定(bind)中。

在我们的例子中,我们已经使用了 netsh,因为我们使用了不同的端口,所以我们的绑定(bind)现在看起来像这样:

netsh http add sslcert ipport=0.0.0.0:10100 certhash=000000089A6679262D845B650FDDE5390F0D86AB appid={000007b4-2d4b-4587-ae99-7a6627476f76} clientcertnegotiation=enable

对于通过 IIS 托管并更改 UploadReadAheadSize 值的用户,上面的论坛帖子指出这可能会导致 CPU 过高,而此解决方案可能会更好。

关于WCF 413 请求实体太大 - 自托管 WebHttpBinding,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22200031/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com