简体   繁体   English

为了让WCF传递大字符串,增加maxStringContentLength的位置在哪里?

[英]Where does one increase maxStringContentLength in order to get WCF to pass large strings?

Okay so I've set up and tested a nice little WCF service. 好的,所以我已经设置并测试了一个不错的小WCF服务。 The client creates a string and passes it into a method on the service and the service then saves it as a file. 客户端创建一个字符串并将其传递给服务上的方法,然后服务将其保存为文件。 Works perfectly with small amounts of test data but when I try it with what it's supposed to do - pass some serialized .net objects - it falls over, with the error 与少量的测试数据完美配合,但是当我尝试它应该做的事情时 - 传递一些序列化的.net对象 - 它会因错误而失败

The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation maximum string content length quota (8192) has been exceeded while reading XML data. 格式化程序在尝试反序列化消息时抛出异常:在读取XML数据时,已超出操作最大字符串内容长度配额(8192)的反序列化请求消息体的错误。 This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader 通过更改创建XML阅读器时使用的XmlDictionaryReaderQuotas对象的MaxStringContentLength属性,可以增加此配额

So I goggle this and find that the MaxStringContentLength property should be set on a "readerQuotas" tag within the tag of the config file, like this: 所以我对此进行了调整,发现应该在配置文件的标记内的“readerQuotas”标记上设置MaxStringContentLength属性,如下所示:

     <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />

So I change it. 所以我改变它。 I change it on the App.config file of my client. 我在我的客户端的App.config文件上更改它。 I change it on the App.config file and the Web.config file of my server. 我在App.config文件和我的服务器的Web.config文件中更改它。 I change it in the App.config file of my unit test project. 我在我的单元测试项目的App.config文件中更改它。 And none of it works - I keep getting the same error. 它都不起作用 - 我一直得到同样的错误。

Interesting, and frustratingly, when I fired up WcfClient.exe to have a look at my service, connected to it and has a look at the config file (Client.dll.config) I was gobsmacked to find that this auto-generated file contained none of my changes and has reset to: 有趣,令人沮丧的是,当我启动WcfClient.exe来查看我的服务,连接到它并查看配置文件(Client.dll.config)时,我发现这个自动生成的文件已经被大惊小怪了我的所有更改都没有重置为:

  <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />

I have no idea where it's getting these values from - nowhere in my entire solution are these being set. 我不知道它从哪里得到这些值 - 在我的整个解决方案中没有任何地方设置这些。 So it must be using defaults, but I don't understand why it's using defaults when I've provided custom Config files at both server and client. 所以它必须使用默认值,但我不明白为什么当我在服务器和客户端都提供自定义配置文件时它使用默认值。

Can anyone help me untangle this? 任何人都可以帮我解开这个吗?

1) Is it possible that your endpoint isn't properly referencing the custom binding? 1)您的端点是否可能未正确引用自定义绑定? Could you post your binding and endpoint sections? 你能发布你的绑定和端点部分吗?

2) WcfTestClient doesn't use your service or client configs to set its own configuration. 2)WcfTestClient不使用您的服务或客户端配置来设置自己的配置。 You'll need to manually edit the Client.dll.config with SvcConfigEditor to set up the WcfTestClient client binding data before executing the service. 在执行服务之前,您需要使用SvcConfigEditor手动编辑Client.dll.config以设置WcfTestClient客户端绑定数据。

You can persist your WcfTestClient configuration changes if you look at the Tools -> Options menu. 如果查看“工具” - >“选项”菜单,可以保留WcfTestClient配置更改。 For more information on WcfTestClient, check this out: http://msdn.microsoft.com/en-us/library/bb552364.aspx 有关WcfTestClient的更多信息,请查看: http//msdn.microsoft.com/en-us/library/bb552364.aspx

You also need to increase the maxReceiveMessageSize etc on the binding itself like this... 你还需要增加绑定本身的maxReceiveMessageSize等...

binding name="BasicHttpsBinding_IService1" maxReceivedMessageSize="34000000" maxBufferPoolSize="34000000" maxBufferSize="34000000" binding name =“BasicHttpsBinding_IService1”maxReceivedMessageSize =“34000000”maxBufferPoolSize =“34000000”maxBufferSize =“34000000”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 带有IIS压缩maxStringContentLength设置的WCF服务 - WCF Service with IIS Compression maxStringContentLength Setting WCF REST抛出HTTP 400错误maxstringcontentlength配额(8192) - WCF REST throws HTTP 400 error maxstringcontentlength quota (8192) exceeded 创建XML阅读器时如何增加MaxStringContentLength大小 - How to increase the MaxStringContentLength size when creating the XML reader 采用默认web.config并增加maxStringContentLength所需的更改 - Changes needed to take a default web.config and increase maxStringContentLength WCF 测试客户端从哪里获取其配置? - From where does the WCF Test Client get its configuration? readerQuotas-&gt; maxStringContentLength到底指什么? - What does readerQuotas --> maxStringContentLength exactly refer to? 通过反射WSHttpBinding在WCF中设置ReaderQuotas.MaxStringContentLength - Set ReaderQuotas.MaxStringContentLength, in WCF via reflection WSHttpBinding 超过MaxStringContentLength? - Over MaxStringContentLength? 如何从Application_BeginRequest中的WCF请求获取方法名称? - How does one get the method name from a WCF Request in Application_BeginRequest? 为什么WCF将空字符串反序列化为有效的枚举 - Why does WCF deserialize empty strings as valid enumerations
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM