gpt4 book ai didi

c# - 将对象发送到 WCF 服务。反序列化时超过 MaxStringContentLength(8192 字节)

转载 作者:太空宇宙 更新时间:2023-11-03 20:31:59 25 4
gpt4 key购买 nike

我创建了一个简单的 WCF Web 服务,它有一个方法:SubmitTicket(flightticket ft, string username, string password)

在客户端,我有一个填写表格(机票)并将其发送到这个新创建的 Web 服务的应用程序。当此机票对象超过 8192 字节时,我收到以下错误:

“反序列化机票类型的对象时出错。读取 XML 数据时已超过最大字符串内容长度配额 (8192)。可以通过更改创建时使用的 XmlDictionaryReaderQuotas 对象上的 MaxStringContentLength 属性来增加此配额XML阅读器”

我在网上做了一些研究,发现我必须将 web.config(服务器)和 app.config(客户端)中的 MaxStringContentLength 设置为更大的数字。问题是,我已经通过阅读各种博客和网站尝试了两个配置文件中所有可能的设置组合,但它仍然因同样的错误而失败!

我附上了我的客户端和服务器配置代码(就目前而言,它在一天内经历了很多很多变化但没有成功)。

我注意到的一件事是,当我更新服务引用时,客户端应用程序上的 configuration.svcinfo 文件似乎总是显示 MaxStringContentLength 为 8192。即使我明确设置了绑定(bind)属性,它似乎也采用了所有默认值。不确定这是否与我的问题完全相关,但值得一提。


这是用于定义端点绑定(bind)的适用 app.config/web.config 代码:

<<<<< 客户端 >>>>>

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IFlightTicketWebService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="65536" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://xx.xx.xx/xxxxxxxx.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IFlightTicketWebService"
contract="FlightTicketWebService.IFlightTicketWebService"
name="BasicHttpBinding_IFlightTicketWebService" />
</client>
</system.serviceModel>
</configuration>

<<<<< 服务器 >>>>>

<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="GSH.FlightTicketWebService.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<system.web>
<httpRuntime maxRequestLength="16384"/>
<compilation debug="true" targetFramework="4.0"/>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
</system.web>

<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IFlightTicketWebService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="65536" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
<services>
<service name="FlightTicketWebService">
<endpoint
name="FlightTicketWebServiceBinding"
address="http://xx.xx.xx/xxxxxxxxxxx.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IFlightTicketWebService"
contract="IFlightTicketWebService"/>
</service>
</services>
</system.serviceModel>
<system.webServer>

最佳答案

我认为问题在于您的服务没有获取其配置,因为您已将服务名称设置为 FlightTicketWebService,而我猜测实际类型在命名空间中。使用命名空间完全限定服务名称,它应该获取您的配置

本质上,这是 WCF 4 默认端点功能的副产品,如果它找不到匹配的配置,它将使用默认配置放置端点

关于c# - 将对象发送到 WCF 服务。反序列化时超过 MaxStringContentLength(8192 字节),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7081739/

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