C# WCF WinCE 解決方案 錯誤提示之:已超過傳入消息(65536)的最大消息大小配額。若要增加配額,請使用相應綁定元素上的 MaxReceivedMessageSize 屬性


網上的解決方案:

 

出現這種錯誤,先去修改服務器端和客戶端的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);

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM