【问题标题】:WCF REST 4.0 The maximum string content length quotaWCF REST 4.0 最大字符串内容长度配额
【发布时间】:2011-11-14 01:33:04
【问题描述】:

我意识到这个问题已经被问了“几十次”

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。

【问题讨论】:

    标签: .net wcf asp.net-mvc-3 wcf-rest


    【解决方案1】:

    查看this question 答案中的代码,了解如何查看设置的最大字符串长度。似乎这种方法对你有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多