为了使WCF传递大字符串,在哪里增加maxStringContentLength? [英] Where does one increase maxStringContentLength in order to get WCF to pass large strings?

查看:32
本文介绍了为了使WCF传递大字符串,在哪里增加maxStringContentLength?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我已经设置并测试了一个不错的WCF服务.客户端创建一个字符串,并将其传递到服务上的方法中,然后该服务将其保存为文件.可以完美地处理少量测试数据,但是当我尝试使用它应该执行的操作时-传递一些序列化的.net对象-它会掉落,并显示错误

Okay so I've set up and tested a nice little WCF service. 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

格式化程序在尝试反序列化消息:反序列化请求主体时出错有关操作最大字符串的消息读取XML数据时超出了内容长度配额(8192).通过更改在创建XML阅读器时使用的XmlDictionaryReaderQuotas对象的MaxStringContentLength属性,可以增加此配额.

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. This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader

因此,我对此进行了查找,发现应该在配置文件的标签内的"readerQuotas"标签上设置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 maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />

因此,我将其更改.我在客户端的App.config文件上对其进行了更改.我在服务器的App.config文件和Web.config文件上对其进行了更改.我在单元测试项目的App.config文件中对其进行了更改.而且都不起作用-我一直收到相同的错误.

So I change it. I change it on the App.config file of my client. I change it on the App.config file and the Web.config file of my server. I change it in the App.config file of my unit test project. And none of it works - I keep getting the same error.

有趣的是,令人沮丧的是,当我启动WcfClient.exe来查看我的服务,连接到该服务并查看配置文件(Client.dll.config)时,我大吃一惊,发现这个自动生成的文件未包含我的任何更改,并且已重置为:

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:

  <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)端点是否可能未正确引用自定义绑定?您可以发布绑定和端点部分吗?

1) Is it possible that your endpoint isn't properly referencing the custom binding? Could you post your binding and endpoint sections?

2)WcfTestClient不使用您的服务或客户端配置来设置其自己的配置.在执行服务之前,您需要使用SvcConfigEditor手动编辑Client.dll.config来设置WcfTestClient客户端绑定数据.

2) WcfTestClient doesn't use your service or client configs to set its own configuration. You'll need to manually edit the Client.dll.config with SvcConfigEditor to set up the WcfTestClient client binding data before executing the service.

如果查看工具"->选项"菜单,则可以保留WcfTestClient配置更改.有关WcfTestClient的更多信息,请查看以下内容: http://msdn.microsoft.com/en-us/library/bb552364.aspx

You can persist your WcfTestClient configuration changes if you look at the Tools -> Options menu. For more information on WcfTestClient, check this out: http://msdn.microsoft.com/en-us/library/bb552364.aspx

这篇关于为了使WCF传递大字符串,在哪里增加maxStringContentLength?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆