WCF REST 4.0 最大字符串内容长度配额
我意识到这个问题已经被问了“几十次”
https://stackoverflow.com/search?q=maxStringContentLength
但是,我仍然没有找到符合我需求的解决方案。我有一个 MVC3 应用程序连接到一个在 WCF 4.0 中构建的 REST 应用程序。
到目前为止,我已经...
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="false" defaultOutgoingResponseFormat="Json" crossDomainScriptAccessEnabled="true" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
</webHttpEndpoint>
</standardEndpoints>
REST 服务器部分可以工作。它允许我传入一个大型模型,并将长字符串值作为其属性之一。当我发布包含大量数据的模型时,我从 MVC 应用程序中验证了这一点,并看到数据已存储在数据库中。
当应用程序完成帖子并尝试请求刚刚保存的数据时,当它尝试序列化我的模型时,我收到了臭名昭著的错误...
读取 XML 时超出了最大字符串内容长度配额 (8192)数据。通过更改创建 XML 阅读器时使用的 XmlDictionaryReaderQuotas 对象上的 MaxStringContentLength 属性,可以增加此配额。
我尝试了很多方法,例如
<bindings>
<webHttpBinding>
<binding>
<readerQuotas maxStringContentLength="2147483647"/>
</binding>
</webHttpBinding>
</bindings>
使用 WebChannelFactory 检索其余数据,然后创建到接口的通道。
string uri = "http://localhost/RestService";
WebChannelFactory<IRestService> _cf = new WebChannelFactory<IRestService>(new Uri(uri));
IRestService service = _cf.CreateChannel();
但到目前为止还没有任何效果。我的 MVC3 应用程序中是否缺少一些可以让模型正确序列化的东西?
我知道 WCF 4 没有 .svc 文件,也没有绑定等,但我不知道需要在 MVC 应用程序中添加什么才能允许 REST 的默认配置被改变。
I realize this question has been asked "dozens of times"
https://stackoverflow.com/search?q=maxStringContentLength
However, I still have not found a solution that matches my needs. I have an MVC3 app connecting to a REST app which was build in WCF 4.0.
So far I have...
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="false" defaultOutgoingResponseFormat="Json" crossDomainScriptAccessEnabled="true" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
</webHttpEndpoint>
</standardEndpoints>
The REST server part works. It allows me to pass in a large model with a long string value as one of it's properties. I verified that from my MVC app as I posted the model with the large bit of data, and saw that the data made it in the DB.
When the app finished the post and tried to request the data it had just saved, I get the infamous error when it tries to serialize my model...
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.
I tried many things such as
<bindings>
<webHttpBinding>
<binding>
<readerQuotas maxStringContentLength="2147483647"/>
</binding>
</webHttpBinding>
</bindings>
I am retrieving the rest data by using the WebChannelFactory and then creating a channel to the interface.
string uri = "http://localhost/RestService";
WebChannelFactory<IRestService> _cf = new WebChannelFactory<IRestService>(new Uri(uri));
IRestService service = _cf.CreateChannel();
But nothing as worked so far. Is there something I am missing in my MVC3 app that will allow the model to be serialized correctly?
I know with WCF 4 there is no .svc file, and no bindings and such, but I am at a loss as to what I need to throw in the MVC app to allow the default configuration of REST to be changed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看此问题的答案中的代码即可了解如何查看最大字符串长度的设置。看来这种方法对你有用。
Look at the code in the answer to this question to see how to see the max string length is set. Seems like that approach would work for you.