错误叫WCF其他服务的使用手机中。长度配额(8192)超过了
-
20-09-2019 - |
题
我有一个WCF其余托管服务在IIS使用。净4RC。后电话服务化,使用手机中。一切正常,直到尺寸的一的数据成员(string)长于8K。在这种情况下,我收到了错误描述的以下指示MaxStringContentLength已经超过。该maxStringContentLength属性端点已经增加,这是正确读的配置文件。
网络配置为:
<services>
<service name="MyServiceServer" >
<endpoint address="http://localhost/MyService" kind="webHttpEndpoint" endpointConfiguration="serviceEndPoint" contract="IMyService">
</endpoint>
</service>
</services>
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="serviceEndPoint" maxReceivedMessageSize="2048000" maxBufferSize="2048000" maxBufferPoolSize="0">
<readerQuotas maxStringContentLength="2048000" maxArrayLength="2048000" maxDepth ="65000"/>
<security mode="None">
<transport clientCredentialType="None"/>
</security>
</standardEndpoint>
</webHttpEndpoint>
</standardEndpoints>
IMyService口被定义为:
public interface IMyService
{
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "/request", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
void MyMehod(<Class Type> obj);
}
完全错误的消息是:
"服务器遇到了错误的处理的请求。异常消息是有一个错误反序列化的目的类型。最大串的内容的长度配额(8192)已经超过,而读XML数据。这种配额可能会增加通过改变MaxStringContentLength财产上XmlDictionaryReaderQuotas对象时使用的创建XML读者。'.看到服务器记录的更多详细信息。除堆栈是:在系统。运行时间。序列化。XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator的读者,布尔verifyObjectName,DataContractResolver dataContractResolver)在系统。运行时间。序列化。手机中。DataContractJsonSerializer.ReadObject(XmlDictionaryReader的读者,布尔verifyObjectName)在系统。ServiceModel.调度员。SingleBodyParameterMessageFormatter.DeserializeRequest(消息对象的参数),在系统。ServiceModel.调度员。DemultiplexingDispatchMessageFormatter.DeserializeRequest(消息对象的参数),在系统。ServiceModel.调度员。UriTemplateDispatchFormatter.DeserializeRequest(消息对象的参数),在系统。ServiceModel.调度员。DispatchOperationRuntime.DeserializeInputs(MessageRpc&rpc)在系统。ServiceModel.调度员。DispatchOperationRuntime.InvokeBegin(MessageRpc&rpc)在系统。ServiceModel.调度员。ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&rpc)在系统。ServiceModel.调度员。ImmutableDispatchRuntime.ProcessMessage31(MessageRpc&rpc)在系统。ServiceModel.调度员。MessageRpc.法(布尔isOperationContextSet)"
解决方案
这一工作,只要确保有一个完整的绝对URL作为你的终结点的地址。如果你得到狡猾的,并试图使用相对路径,或者如果你忽略。svc它将炸弹带有奇怪的读者配额的错误,一旦请求获得太大--
我会文件,这在一个错误WCF因为无论是:
- 相对的网址应该不允许(和适当的例外扔)
或
- 读者配额应与相对路径以及
其他提示
插入到你的web.config:
<configuration>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="webHttpBindingConfig">
<readerQuotas maxStringContentLength="2048000" />
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>
</configuration>
和插入属性bindingConfiguration = “webHttpBindingConfig” 到您的端点
我有类似的问题,但与.NET 3.5
我对服务器日志中没有问题,所以这个问题是在客户端上。 的似乎与最大值的配置增加未读取和使用强> ...
因此,我解决明确的WebChannelFactory的构造使所述端点的名称,使用另一种过载。
WAS:
WebChannelFactory<IWKRestTest> factory = new WebChannelFactory<IWKRestTest>(new Uri(XXX));
factory.Credentials.UserName.UserName = K_USERNAME;
factory.Credentials.UserName.Password = K_PASSWORD;
IWKRestTest proxy = factory.CreateChannel();
时:
WebChannelFactory<IWKRestTest> factory = new WebChannelFactory<IWKRestTest>("IWKRestTestService");
和在App.config有:
URI是在端点节点表示但你还可以找到bindingConfiguration等等,让所有新增加的限制,现在的作品。