2014-09-04 100 views
0

我有一個應用程序,其中在我的一個方法中,我將文件傳輸到服務器。無法通過nettcp綁定上傳大文件和transfermode =「緩衝」

我可以輕鬆地上傳大約50 KB的文件。但是我的最大限制將在3 MB左右。

我WCR服務託管在Windows服務與NetTcpBinding的

我的Windows配置,那麼

<configuration> 
    <system.serviceModel> 
    <services> 
     <service name="BTWAServerWindowsService.BatchManagementService" 
       behaviorConfiguration ="BatchManagementService"> 
     <host> 
      <baseAddresses> 
      <add baseAddress="net.tcp://localhost:9999/BatchManagementService" /> 
      </baseAddresses> 
     </host> 
     <endpoint name="BatchManagementServiceEndPoint" 
     address ="" 
     binding="netTcpBinding" 
     contract="BTWAServerWindowsService.IBatchManagementService"> 
     </endpoint> 
     <endpoint name="BatchManagementServiceMetadataPoint" address="mex" 
       binding="mexTcpBinding" 
       contract="IMetadataExchange"/> 
     </service>  
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="BatchManagementService"> 
      <serviceMetadata httpGetEnabled="False"/> 
      <serviceDebug includeExceptionDetailInFaults="False" /> 
     </behavior>  
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 
</configuration> 

我的客戶的配置是

<configuration> 
    <system.serviceModel> 
    <bindings> 
     <netTcpBinding> 
     <binding name="BatchManagementServiceEndPoint" closeTimeout="00:10:00" 
      openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" 
      transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" 
      hostNameComparisonMode="StrongWildcard" listenBacklog="524288" 
      maxBufferPoolSize="524288" maxBufferSize="524288" maxConnections="524288" 
      maxReceivedMessageSize="524288"> 
      <readerQuotas maxDepth="524288" maxStringContentLength="524288" 
      maxArrayLength="524288" maxBytesPerRead="524288" maxNameTableCharCount="524288" /> 
      <reliableSession ordered="true" inactivityTimeout="00:10:00" 
      enabled="false" /> 
      <security mode="Transport"> 
      <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" /> 
      <message clientCredentialType="Windows" /> 
      </security> 
     </binding>  
     </netTcpBinding> 
    </bindings> 
    <client> 
     <endpoint address="net.tcp://localhost:9999/BatchManagementService" 
     binding="netTcpBinding" bindingConfiguration="BatchManagementServiceEndPoint" 
     contract="BTWABatchManagement.IBatchManagementService" name="BatchManagementServiceEndPoint" />  
    </client> 
    </system.serviceModel> 
</configuration> 

此刻我不是在改變位置轉移模式爲流式傳輸,因爲還有其他多種方法

請建議我將配置更改爲什麼將我的文件限制增加到4 MB

回答

1

在您的服務端app.config中的netTcpBinding以及客戶端app.config中對以下屬性進行更改

maxBufferPoolSize="1073741824" maxBufferSize="1073741824" maxConnections="10" 
      maxReceivedMessageSize="1073741824"> 
      <readerQuotas maxDepth="32" maxStringContentLength="2147483647" 
      maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 

這些屬性的最大值爲2147483647

<bindings> 
     <netTcpBinding> 
     <binding name="BatchManagementServiceEndPoint" closeTimeout="00:10:00" 
      openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" 
      transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" 
      hostNameComparisonMode="StrongWildcard" listenBacklog="524288" 
      maxBufferPoolSize="1073741824" maxBufferSize="1073741824" maxConnections="10" 
      maxReceivedMessageSize="1073741824"> 
      <readerQuotas maxDepth="32" maxStringContentLength="2147483647" 
      maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
      <reliableSession ordered="true" inactivityTimeout="00:10:00" 
      enabled="false" /> 
      <security mode="Transport"> 
      <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" /> 
      <message clientCredentialType="Windows" /> 
      </security> 
     </binding>  
     </netTcpBinding> 
</bindings> 

希望這有助於

+0

感謝德拉納。剛剛完成就像http://www.wcftutorial.net/WCF-Transfer-mode.aspx中提到的那樣 – 2014-09-04 06:48:17