我需要将maxStringContentLength更改为大于8192的值,但没有成功。如果我的WCF服务接收的数据量大于8192字节,它将生成一个异常。我已经用尽了我的搜索,但似乎没有任何帮助。我应该指出的是,异常来自服务器。忘记客户端,因为我看到的异常是直接从服务器上的WCF生成的。以下是我的web.config设置:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="DevServiceBehavior" >
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="DeveloperService"
behaviorConfiguration="DevServiceBehavior" >
<endpoint address="mtom"
binding="basicHttpBinding"
bindingConfiguration="Binding_DevService"
contract="DeveloperService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint contract="IMetadataExchange"
binding="mexHttpBinding"
address="mex" />
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="Binding_DevService"
messageEncoding="Mtom"
openTimeout="00:02:00"
sendTimeout="00:02:00"
maxBufferPoolSize ="41943040"
maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="500"
maxArrayLength="20000000"
maxStringContentLength="20000000" />
</binding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true"/>
</system.serviceModel>发布于 2011-08-17 21:21:22
默认情况下,WCF的最新版本实际上是默认设置,而json是默认设置。不清楚的是WCF使用的是哪种默认绑定。原来是webHttpBinding。您还将在web上看到大量示例,显示应用于服务方法的属性,例如WebGet。该方法根本不需要任何属性。要使maxStringContentLength生效,您需要正确设置绑定和行为。以下是web.config文件中的正确条目:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="jsonBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="DevServiceBehavior" >
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="DeveloperService" behaviorConfiguration="DevServiceBehavior" >
<endpoint address="" binding="webHttpBinding" contract="DeveloperService" bindingConfiguration="webHttpBindingDev" behaviorConfiguration="jsonBehavior">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="webHttpBindingDev">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</webHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>发布于 2011-08-16 05:00:40
同时更新你的客户端配置。在中设置Reader的配额,在binding部分设置Reader的属性。
https://stackoverflow.com/questions/7065543
复制相似问题