首页 > 解决方案 > 如何增加 ASP.Net Core SOAP ServiceContract 中的字节限制?

问题描述

我有一个与 Quickbooks Web 连接器通信的 ASP.Net Core 3 应用程序。

我无法弄清楚如何将允许的最大字节数从 8192 增加到更大的值。大多数 Quickbooks 请求包含比这更多的数据。

我的服务合同中有以下内容:

QBWC.asmx

[ServiceContract(Namespace = @"http://developer.intuit.com/")]
public interface IQBWCService
{
    [OperationContract]
    int receiveResponseXML(string ticket, string response, string hresult, string message);
}

在我的 Startup.cs

app.UseSoapEndpoint<IQBWCService>("/qbwc/qbwc.asmx", new BasicHttpBinding(), SoapSerializer.XmlSerializer, true);

当 Quickbooks 尝试发送大于 8192 字节的任何内容时,我收到以下错误:

System.Xml.XmlException: The maximum string content length quota (8192) has been exceeded while reading XML data. This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader.

我在任何地方都找不到任何名为 MaxStringContentLength 的东西。

对我做错了什么有帮助吗?

标签: asp.net-coresoap

解决方案


想通了。更改此行

app.UseSoapEndpoint<IQBWCService>("/qbwc/qbwc.asmx", new BasicHttpBinding(), SoapSerializer.XmlSerializer, true);

对此

var httpBinding = new BasicHttpBinding();
httpBinding.ReaderQuotas.MaxStringContentLength = 5000000;  
app.UseSoapEndpoint<IQBWCService>("/qbwc/qbwc.asmx", httpBinding, SoapSerializer.XmlSerializer, true);

推荐阅读