WCF通过wsHttpBinding传输数组长度大于16384的解决方法

当数返回的数组长度≤16383时一切正常,当返回数组长度≥16384时则会出现异常.配置文件中的

<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384000"
maxBytesPerRead="4096" maxNameTableCharCount="16384000" />

都改成了上面的值,结果还是一样. 在网上找了很多,有的说要换成[流模式]来处理,这样的话服务器端与客户端都得改动;有的说改上面的值和接收超时时间 , 相信说这些的人根本就没有测试过,如果有试过的都知道是没有效果的. 经过长时间的网上找资料和微软的相关帮助.需要做下面的修改,希望能帮到一些WCF的新人们

服务器端:

<!--name 必须与代码中的host实例初始化的服务一样 behaviorConfiguration 行为配置 -->
<service name="DRP.myServer" behaviorConfiguration="DRP.myServerDataBehavior">

    <host>
<!--添加调用服务地址-->
<baseAddresses>
<add baseAddress="http://localhost:8000/myServer"/>
</baseAddresses>
</host>
<!--添加契约接口   contract="WcfDemo.IService1" WcfDemo.IService1为契约接口   binding="wsHttpBinding" wsHttpBinding为通过Http调用-->
     <endpoint binding="wsHttpBinding" behaviorConfiguration="myEndpointBehavior" contract="DRP_BaseData.IServiceMyServer" bindingConfiguration="ServerBinding">
</endpoint>
</service>

红色的属性默认无, 需要手工加上

<behaviors>
<endpointBehaviors>
<behavior name="myEndpointBehavior">
<dataContractSerializer maxItemsInObjectGraph="65536000"/>
</behavior>
</endpointBehaviors>
<!--下面的serviceBehaviors不设置也可以通过-->
<serviceBehaviors>
<behavior name="DRP.myServerDataBehavior">
<!-- 为避免泄漏元数据信息,请在部署前将以下值设置为 false 并删除上面的元数据终结点-->
<serviceMetadata httpGetEnabled="true"/>
<!-- 要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息-->
<serviceDebug includeExceptionDetailInFaults="true"/>
<!--serviceThrottling maxConcurrentCalls="3000" maxConcurrentInstances="3000" maxConcurrentSessions="30000"/-->
<dataContractSerializer maxItemsInObjectGraph="65536000"/>
</behavior>
   </serviceBehaviors>
</behaviors>

客户端

<behaviors>
<endpointBehaviors>
<behavior name="myEndpointBehavior">
<dataContractSerializer maxItemsInObjectGraph="65536000"/>
</behavior>
</endpointBehaviors> 
</behaviors>

<endpoint address="http://localhost:8000/myServer" binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IServiceMyServer" contract="MyServerReference.IServiceMyServer"
name="MyServer" behaviorConfiguration="myEndpointBehavior" />

当然 bindingConfiguration配置中的一些相关的数据大小,超时时间也需要设置

Via:http://hi.baidu.com/mark58/blog/item/3b6b288de8a5911eb21bba2c.html

posted @ 2013-02-25 19:25  therockthe  阅读(450)  评论(0)    收藏  举报