gpt4 book ai didi

c# - WCF 异常 : The maximum message size quota for incoming messages (65536) has been exceeded

转载 作者:太空狗 更新时间:2023-10-29 17:59:39 25 4
gpt4 key购买 nike

当我调用 WCF 服务时出现异常:

The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.

当我在 http 上使用 Wireshark 数据包分析器过滤器时,发送的最大数据包为 1226 字节,远低于 65536 字节的限制。对抛出此异常的原因有何建议?

Screendump from wireshark

协议(protocol)长度信息

服务器堆栈跟踪:

at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
...
<binding
name="WSHttpBinding_IService"
closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false"
transactionFlow="false"
hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas
maxDepth="32"
maxStringContentLength="8192"
maxArrayLength="16384"
maxBytesPerRead="4096"
maxNameTableCharCount="16384" />
<reliableSession
ordered="true"
inactivityTimeout="00:10:00"
enabled="false" />
<security
mode="Message">
<transport
clientCredentialType="Windows"
proxyCredentialType="None"
realm="" />
<message
clientCredentialType="Certificate"
negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>

我怀疑导致异常的代码:

public LoanPlan CalculateLoanPlans(string productName)
{
var loanPlan = new LoanPlan
{
Details = new[]
{
new PlanDetails {LoanAmount = 5000, Periods = 6},
new PlanDetails {LoanAmount = 5000, Periods = 12},
new PlanDetails {LoanAmount = 5000, Periods = 24},

new PlanDetails {LoanAmount = 10000, Periods = 6},
new PlanDetails {LoanAmount = 10000, Periods = 12},
new PlanDetails {LoanAmount = 10000, Periods = 24},

new PlanDetails {LoanAmount = 15000, Periods = 6},
new PlanDetails {LoanAmount = 15000, Periods = 12},
new PlanDetails {LoanAmount = 15000, Periods = 24},

new PlanDetails {LoanAmount = 20000, Periods = 6},
new PlanDetails {LoanAmount = 20000, Periods = 12},
new PlanDetails {LoanAmount = 20000, Periods = 24},

new PlanDetails {LoanAmount = 30000, Periods = 6},
new PlanDetails {LoanAmount = 30000, Periods = 12},
new PlanDetails {LoanAmount = 30000, Periods = 24},

new PlanDetails {LoanAmount = 40000, Periods = 6},
new PlanDetails {LoanAmount = 40000, Periods = 12},
new PlanDetails {LoanAmount = 40000, Periods = 24},

new PlanDetails {LoanAmount = 50000, Periods = 6},
new PlanDetails {LoanAmount = 50000, Periods = 12},
new PlanDetails {LoanAmount = 50000, Periods = 24}
},
TaxProcent = _taxPercent,
};
Parallel.ForEach(loanPlan.Details, detail =>
{
var result = Calculate(productName, Convert.ToInt32(detail.LoanAmount), detail.Periods, null);

detail.ActualPaymentCost = result.ActualPaymentCost;
detail.CreditCost = result.CreditAmount;
detail.MonthlyPayment = result.MonthlyPayment;
detail.MonthlyPaymentCost = result.MonthlyPaymentCredit;
});

var firstDetail = loanPlan.Details[0];
var firstResult = Calculate(productName, Convert.ToInt32(firstDetail.LoanAmount), firstDetail.Periods, null);

loanPlan.MonthlyFee = firstResult.MonthlyFee;
loanPlan.MonthlyInterest = firstResult.MonthlyInterest;

return loanPlan;
}

Calculate 方法包含服务调用。

最佳答案

增加服务器和客户端的 maxStringContentLength & maxArrayLength="2147483647"。检查下面的详细解释的链接

http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/f570823a-8581-45ba-8b0b-ab0c7d7fcae1

关于c# - WCF 异常 : The maximum message size quota for incoming messages (65536) has been exceeded,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9410873/

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