整容说文库 > 程序代码 > 教育资讯

WCF调用maxReceivedMessageSize属性设置

来源:学生作业帮助网 编辑:整容说文库 时间:2019/06/25 19:49:47 程序代码
WCF调用maxReceivedMessageSize属性设置程序代码
WCF服务端配置文件如下: 
<netTcpBinding>
        <binding name="bd" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false" transferMode="Streamed" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="5242880" maxBufferSize="655360" maxConnections="10" maxReceivedMessageSize="655360">
          <readerQuotas maxDepth="320" maxStringContentLength="81920" maxArrayLength="163840" maxBytesPerRead="40960" maxNameTableCharCount="163840" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
          <security mode="None">
            <transport clientCredentialType="Windows" />
            <message clientCredentialType="Windows" />
          </security>
        </binding>


客户端调用配置文件如下:
<netTcpBinding>
        <binding name="NetTcpBinding_IWCFServices" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
          transactionFlow="false" transferMode="Streamed" transactionProtocol="OleTransactions"
          hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288"
          maxBufferSize="655360" maxConnections="10" maxReceivedMessageSize="655360">
          <readerQuotas maxDepth="320" maxStringContentLength="81920"
            maxArrayLength="163840" maxBytesPerRead="40960" maxNameTableCharCount="163840" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00"
            enabled="false" />
          <security mode="None">
            <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
            <message clientCredentialType="Windows" />
          </security>
        </binding>
      </netTcpBinding>


发现修改设置了maxReceivedMessageSize的大小后不起作用,大消息大小超过65536时,依旧报错。
现在如何修改?等......
你传得是什么格式的数据?估计应该是maxItemsInObjectGraph这个超过了报的错吧
我传的一个list<object>集合,和这个有关系吗
错误提示:
    已超过传入消息(65536)的最大消息大小配额。若要增加配额,请使用相应绑定元素上的 MaxReceivedMessageSize 属性。
引用 3 楼 wwwszx2002 的回复:
错误提示:
   已超过传入消息(65536)的最大消息大小配额。若要增加配额,请使用相应绑定元素上的 MaxReceivedMessageSize 属性。

MaxReceivedMessageSize 不够用了啊,增大吧。。
增加设置后不起作用,我加了几个零了,都不管用。大哥们,遇到过类似问题吗
遇到过,修改binging的MaxReceivedMessageSize 后就没错了
对比了下你的binding只发现maxStringContentLength="81920"这个我也设置成了和MaxReceivedMessageSize 一样的大小
我试一试,楼上的办法
还是报超出范围,需要增加配额的错误,是不是和我传的类型有问题,我传的是linq to entities,生成的实体集合,当超过100个数据量的时候就出问题了,但是保存后的xml文件也很小,只有20kb。
这种错误只有一种可能性,那就是你的绑定配置并非你程序调用的,可能是你有多个绑定(你没有给出完整的配置文件),也可能是你程序调用时未使用配置文件中的绑定,自己设置了绑定(这种可能比较大,不懂的人往往乱射)。
服务端:
<system.serviceModel>
    <client>
      <endpoint address="http://219.224.109.56:500/DisService.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IDisService" contract="ConfigService.IDisService" name="WSHttpBinding_IDisService">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
    </client>
    <services>
      <service behaviorConfiguration="sb" name="**************">
        <endpoint address="net" binding="netTcpBinding" bindingConfiguration="bd" contract="***************">
         <identity>
           <dns value="localhost" />
         </identity>
        </endpoint>
        <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:5353" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <bindings>
      <netTcpBinding>
        <binding name="bd" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false" transferMode="Streamed" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288" maxBufferSize="655360" maxConnections="10" maxReceivedMessageSize="655360">
          <readerQuotas maxDepth="320" maxStringContentLength="655360" maxArrayLength="163840" maxBytesPerRead="40960" maxNameTableCharCount="163840" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
          <security mode="None">
            <transport clientCredentialType="Windows" />
            <message clientCredentialType="Windows" />
          </security>
        </binding>
      </netTcpBinding>
      <wsHttpBinding>
        <binding name="WSHttpBinding_IDisService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
          <security mode="None">
            <transport realm="" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="sb">
          <serviceMetadata />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

客户端:

<system.serviceModel>
    <bindings>
      <netTcpBinding>
        <binding name="NetTcpBinding_IWCFServices" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
          transactionFlow="false" transferMode="Streamed" transactionProtocol="OleTransactions"
          hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288"
          maxBufferSize="655360" maxConnections="10" maxReceivedMessageSize="655360">
          <readerQuotas maxDepth="320" maxStringContentLength="655360"
            maxArrayLength="163840" maxBytesPerRead="40960" maxNameTableCharCount="163840" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00"
            enabled="false" />
          <security mode="None">
            <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
            <message clientCredentialType="Windows" />
          </security>
        </binding>
      </netTcpBinding>
    </bindings>
    <client>
      <endpoint address="net.tcp://localhost:5353/net" binding="netTcpBinding"
        bindingConfiguration="NetTcpBinding_IWCFServices" contract="WCFServices.IWCFServices"
        name="NetTcpBinding_IWCFServices">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>

服务端有多个绑定,但我使用的是NetTcpBinding
在客户端调用时,直接new出来的代理类,并没有进行属性的设置
问题已经解决,原来是为了配置服务端的ip和port,在client类中new了NetTcpBinding,所以就根本没有调用配置文件。忘记已经修改过了,郁闷一天!
程序代码