我有一个可以接受byte[]
. 我正在使用创建客户端HttpClient
并收到以下错误。我在网上读到,您必须readerQuotas
在服务器和客户端上都设置,但是如何在 上设置这些设置HttpClient
?
错误:
反序列化 RTM.API.Resources.UGCRequest 类型的对象时出错。读取 XML 数据时,已超出最大数组长度配额 (16384) 或对象图中的最大项目配额。这些配额可以通过更改 XmlDictionaryReaderQuotas 上的 MaxArrayLength 属性或 MaxItemsInObjectGraph 设置来增加。
服务器配置:
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" maxBufferSize="2147483647"/>
<standardEndpoint name="DirectoryEndpoint"/>
</webHttpEndpoint>
</standardEndpoints>
<services>
<service name="API.Service.UGCService" behaviorConfiguration="DataServiceBehavior">
<endpoint contract="API.Service.UGCService" kind="webHttpEndpoint" endpointConfiguration="" binding="webHttpBinding" bindingConfiguration="BigHttpBinding"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DataServiceBehavior">
<serviceDebug includeExceptionDetailInFaults="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483644"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="BigHttpBinding" transferMode="Buffered" maxReceivedMessageSize="2147483647" >
<readerQuotas maxArrayLength="2147483647" maxDepth="2147483647" maxStringContentLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
</binding>
</webHttpBinding>
</bindings>
客户端代码:
using (HttpClient client = new HttpClient(apiPath))
{
using (HttpRequestMessage request = new HttpRequestMessage(method, finalUrl))
{
request.Headers.Accept.AddString("application/json");
request.Headers.Add("Authorization", sb.ToString());
if (method == "POST" || method == "PUT")
{
if (requestBody.Count() == 0)
request.Headers.ContentLength = 0;
else
{
request.Content = HttpContent.Create(APM6.Utils.Serialize(requestBody), "application/json");
}
}
using (HttpResponseMessage response = client.Send(request))
{
return response.Content.ReadAsString();
}
}
}