Java自学者论坛

 找回密码
 立即注册

手机号码,快捷登录

恭喜Java自学者论坛(https://www.javazxz.com)已经为数万Java学习者服务超过8年了!积累会员资料超过10000G+
成为本站VIP会员,下载本站10000G+会员资源,会员资料板块,购买链接:点击进入购买VIP会员

JAVA高级面试进阶训练营视频教程

Java架构师系统进阶VIP课程

分布式高可用全栈开发微服务教程Go语言视频零基础入门到精通Java架构师3期(课件+源码)
Java开发全终端实战租房项目视频教程SpringBoot2.X入门到高级使用教程大数据培训第六期全套视频教程深度学习(CNN RNN GAN)算法原理Java亿级流量电商系统视频教程
互联网架构师视频教程年薪50万Spark2.0从入门到精通年薪50万!人工智能学习路线教程年薪50万大数据入门到精通学习路线年薪50万机器学习入门到精通教程
仿小米商城类app和小程序视频教程深度学习数据分析基础到实战最新黑马javaEE2.1就业课程从 0到JVM实战高手教程MySQL入门到精通教程
查看: 576|回复: 0

C# WCF WinCE 解决方案 错误提示之:已超过传入消息(65536)的最大消息大小配额。若要增加配额,请使用相应绑定元素上的 MaxReceivedMessageSize 属性

[复制链接]
  • TA的每日心情
    奋斗
    2024-11-24 15:47
  • 签到天数: 804 天

    [LV.10]以坛为家III

    2053

    主题

    2111

    帖子

    72万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    积分
    726782
    发表于 2021-6-7 17:57:10 | 显示全部楼层 |阅读模式

    网上的解决方案:

     

    出现这种错误,先去修改服务器端和客户端的MaxReceivedMessageSize值,如果还报错那么查看你的代码调用了是不是new了一个新的BasicHttpBinding对象,如果是new了新的那么你的webconfig根本就没有被调用,在new的时候要将 <binding name="DataSyncService" 中的name值作为参数传进去,或者是在代码里重新设置MaxReceivedMessageSize值

    第一种

    DataSyncServiceClient service = new DataSyncServiceClient(new BasicHttpBinding("DataSyncService"), new EndpointAddress(new Uri(con)));

    第二种

    DataSyncServiceClient service = new DataSyncServiceClient(new BasicHttpBinding(), new EndpointAddress(new Uri(con)));

    (service.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = int.MaxValue;
    (service.Endpoint.Binding as BasicHttpBinding).MaxBufferPoolSize = int.MaxValue;
    (service.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = int.MaxValue;

    我自己项目中的问题:

                    //SMC.Binding binding = U8ServiceClient.CreateDefaultBinding();
                    //string remoteAddress = U8ServiceClient.EndpointAddress.Uri.ToString();
                    //EndpointAddress endpoint = new EndpointAddress(remoteAddress);
                    //U8Client = new U8ServiceClient(binding, endpoint);
                    //SessionID = U8Client.StartSession();

    我们之前是用上面的这个方法来的:即使我在服务器端设置了:

     maxReceivedMessageSize="2147483647"

    <dataContractSerializer maxItemsInObjectGraph="2147483647" />

    也还是不起作用。

     

    <?xml version="1.0"?>
    <configuration>
        <system.web>
            <compilation debug="true" targetFramework="4.0">
                <assemblies>
                    <add assembly="Interop.U8Login, Version=1.14.0.0, Culture=neutral, PublicKeyToken=79A4E7AD54EEABCA"/></assemblies></compilation>
        <customErrors mode="Off"/>
      </system.web>
        <appSettings>
            <add key="defaultConnection" value="sqlCon"/>
            <add key="DALAssemblyName" value="HZYA.DALSQLServer"/>
            <add key="DALFactoryType" value="HZYA.DALSQLServer.DALMSSqlFactory"/>
        <add key="SessionTimeOut" value="00:30:00"/>
        </appSettings>
        <connectionStrings>
            <!--<add name="sqlCon" connectionString="Data Source=CQY-PC\SQLEXPRESS2005;Initial Catalog=UFDATA_001_2010;User ID=sa;Password=sasa" providerName="System.Data.SqlClient"/>
            <add name="System" connectionString="Data Source=CQY-PC\SQLEXPRESS2005;Initial Catalog=UFSysTem;User ID=sa;Password=sasa" providerName="System.Data.SqlClient"/>
            <add name="Barcode" connectionString="Data Source=CQY-PC\SQLEXPRESS2005;Initial Catalog=Barcode;User ID=sa;Password=sasa" providerName="System.Data.SqlClient"/>-->
        <add name="sqlCon" connectionString="Data Source=wuyf\sql2005;Initial Catalog=UFDATA_001_2012;User ID=sa;Password=sasa" providerName="System.Data.SqlClient"/>
        <add name="System" connectionString="Data Source=wuyf\sql2005;Initial Catalog=UFSysTem;User ID=sa;Password=sasa" providerName="System.Data.SqlClient"/>
        <add name="Barcode" connectionString="Data Source=wuyf\sql2005;Initial Catalog=Barcode;User ID=sa;Password=sasa" providerName="System.Data.SqlClient"/>
        </connectionStrings>
        <system.serviceModel>
            <services>
                <service name="CommonService" behaviorConfiguration="ServiceBehavior">
                    <endpoint address="" binding="wsHttpBinding" contract="ICommonService" bindingConfiguration="LargeSizeWsHttpBinding"/>
                    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
                    <endpoint address="basic" binding="basicHttpBinding" contract="ICommonService" bindingConfiguration="LargeSizeBasicHttpBinding"/>
                </service>
                <service name="BarcodeService" behaviorConfiguration="ServiceBehavior">
                    <endpoint address="" binding="wsHttpBinding" contract="IBarcodeService"/>
                    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
                    <endpoint address="basic" binding="basicHttpBinding" contract="IBarcodeService"/>
                </service>
                <service name="PrintService" behaviorConfiguration="ServiceBehavior">
                    <endpoint address="" binding="wsHttpBinding" contract="IPrintService"/>
                    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
                    <endpoint address="basic" binding="basicHttpBinding" contract="IPrintService"/>
                </service>
          <service name="LoginService" behaviorConfiguration="ServiceBehavior" >
            <!--<endpoint address="" binding="wsHttpBinding" contract="ILoginService" bindingConfiguration="NoneSecurity" />
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>-->
            <endpoint address="basic" binding="basicHttpBinding" contract="ILoginService"/>
          </service>
          <service name="U8Service" behaviorConfiguration="ServiceBehavior" >
            <endpoint address="" binding="wsHttpBinding" contract="IU8Service" />
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
            <endpoint address="basic" binding="basicHttpBinding" contract="IU8Service"/>
          </service>
          <!--<service name="U8Service" behaviorConfiguration="ServiceBehavior" >
            <endpoint address="" binding="wsHttpBinding" contract="ILoginService" bindingConfiguration="NoneSecurity" />
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
            <endpoint address="basic" binding="basicHttpBinding" contract="IU8Service"/>
          </service>-->
            </services>
            <bindings>
                <basicHttpBinding>
                    <binding name="LargeSizeBasicHttpBinding" maxBufferPoolSize="2147483647" receiveTimeout="00:00:10" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
                        <readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="2147483647" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647"/>
                    </binding>
                </basicHttpBinding>
                <wsHttpBinding>
            <binding name="LargeSizeWsHttpBinding" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
                        <readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="2147483647" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647"/>
                    </binding>
            <binding name="NoneSecurity" receiveTimeout="00:00:50" maxBufferPoolSize="12000000" maxReceivedMessageSize="12000000" useDefaultWebProxy="false">
              <readerQuotas maxStringContentLength="12000000" maxArrayLength="12000000"/>
              <reliableSession enabled="true"/>
              <security mode="None">
                <message establishSecurityContext="true"/>
              </security>
            </binding>
          </wsHttpBinding>
            </bindings>
            <behaviors>
                <serviceBehaviors>
                    <behavior name="ServiceBehavior">
                        <serviceMetadata httpGetEnabled="true"/>
                        <serviceDebug includeExceptionDetailInFaults="true"/>
              <dataContractSerializer maxItemsInObjectGraph="2147483647" />                 </behavior>
                    <behavior name="">
                        <serviceMetadata httpGetEnabled="true"/>
                        <serviceDebug includeExceptionDetailInFaults="false"/>
                    </behavior>
                </serviceBehaviors>
            </behaviors>
            <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
      </system.serviceModel>
        <system.webServer>
            <directoryBrowse enabled="true" showFlags="Date, Time, Size, Extension, LongDate"/>
        </system.webServer>
    </configuration>

     

     

     直到看到网上的这篇文章后,我修改了我的客户端 binding 类型为 basehttpbinding  后,才解决了。

    代码如下:

                    BasicHttpBinding binding = new BasicHttpBinding();
                    binding.MaxReceivedMessageSize = int.MaxValue;
                    binding.MaxBufferPoolSize = int.MaxValue;
                    binding.MaxBufferSize = int.MaxValue;
                    string remoteAddress = U8ServiceClient.EndpointAddress.Uri.ToString();
                    EndpointAddress endpoint = new EndpointAddress(remoteAddress);
                    U8Client = new U8ServiceClient(binding, endpoint);

     

     

     

     

     

    哎...今天够累的,签到来了1...
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|手机版|小黑屋|Java自学者论坛 ( 声明:本站文章及资料整理自互联网,用于Java自学者交流学习使用,对资料版权不负任何法律责任,若有侵权请及时联系客服屏蔽删除 )

    GMT+8, 2024-12-23 08:02 , Processed in 0.058128 second(s), 27 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2021, Tencent Cloud.

    快速回复 返回顶部 返回列表