XML 无法验证,因为 Base64 编码字符串太大
XML cannot be validated because of too big Base64 encoded string
我有一个在 Visual Studio 2017 年使用 .NET 4.0 框架编译的 C# 创建的 SOAP 服务。
我在调试时将服务部署到 IIS Express,并部署到 IIS 管理器站点。
在这两种服务上,当我 post 一个带有 810 万个字符的(大)Base64 编码字符串(PDF 文件)的 XML 时,我 运行 遇到以下错误:
System.Web.Services.Protocols.SoapException:
Server was unable to process request.
Object reference not set to an instance of an object.
at System.Web.Services.Protocols.SoapServerProtocolHelper.GetRequestElement()
at System.Web.Services.Protocols.Soap12ServerProtocolHelper.RouteRequest()
at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)
我已经尝试将 web.config
文件和 applicationhost.config
文件中的“最大允许内容长度”增加到大约 3GB。这没有影响,但我也没想到会有任何结果,因为错误实际上并没有说明它有内容太大的问题。
当我 post 相同的 XML 和另一个小得多的 Base64 字符串时,它确实从 XML 创建了一个正确的对象,没有任何问题。
我还检查了多个在线转换器的 Base64 字符串是否正确。他们在尺寸方面也有很多问题,但我可以确认字符串。
奇怪的是调试的时候连WebService都不进去class.
顺便说一句,代码中的字段是一个字节数组,在 XSD 中定义为 base64Binary。
我不能共享 Base64 字符串本身,因为在这种情况下它包含敏感信息,也因为它的大小。
我该如何解决这个问题?
更新
还尝试设置“为网站和项目使用 64 位版本的 IIS Express”,但这对天气没有帮助。
问题是最大请求长度。 XML 的大小比 IIS 中设置的默认限制长。这导致切割 XML,从而产生 invalid/incomplete XML 文件。
可以直接在 web.config 文件中更改此配置:
<system.web>
<httpRuntime maxRequestLength="2147483647" />
</system.web>
或在 IIS 管理器中:
- 打开网站
- 打开配置编辑器
- 在部分转到系统。web/httpRuntime
- 更改 maxRequestLength 属性
我有一个在 Visual Studio 2017 年使用 .NET 4.0 框架编译的 C# 创建的 SOAP 服务。
我在调试时将服务部署到 IIS Express,并部署到 IIS 管理器站点。 在这两种服务上,当我 post 一个带有 810 万个字符的(大)Base64 编码字符串(PDF 文件)的 XML 时,我 运行 遇到以下错误:
System.Web.Services.Protocols.SoapException:
Server was unable to process request.
Object reference not set to an instance of an object.
at System.Web.Services.Protocols.SoapServerProtocolHelper.GetRequestElement() at System.Web.Services.Protocols.Soap12ServerProtocolHelper.RouteRequest() at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)
我已经尝试将 web.config
文件和 applicationhost.config
文件中的“最大允许内容长度”增加到大约 3GB。这没有影响,但我也没想到会有任何结果,因为错误实际上并没有说明它有内容太大的问题。
当我 post 相同的 XML 和另一个小得多的 Base64 字符串时,它确实从 XML 创建了一个正确的对象,没有任何问题。
我还检查了多个在线转换器的 Base64 字符串是否正确。他们在尺寸方面也有很多问题,但我可以确认字符串。
奇怪的是调试的时候连WebService都不进去class.
顺便说一句,代码中的字段是一个字节数组,在 XSD 中定义为 base64Binary。
我不能共享 Base64 字符串本身,因为在这种情况下它包含敏感信息,也因为它的大小。
我该如何解决这个问题?
更新 还尝试设置“为网站和项目使用 64 位版本的 IIS Express”,但这对天气没有帮助。
问题是最大请求长度。 XML 的大小比 IIS 中设置的默认限制长。这导致切割 XML,从而产生 invalid/incomplete XML 文件。
可以直接在 web.config 文件中更改此配置:
<system.web>
<httpRuntime maxRequestLength="2147483647" />
</system.web>
或在 IIS 管理器中:
- 打开网站
- 打开配置编辑器
- 在部分转到系统。web/httpRuntime
- 更改 maxRequestLength 属性