2013-03-14 64 views
2

我正在製作WCF服務來傳輸文件。我只有基本的WCF理解,並遵循MSDN教程:WCF Tutorial 我開始使用字節數組來傳輸文件,但只要文件有一點點大(100kb就足夠了),它會因錯誤的請求而失敗。 我遵循另一個指南,並改爲使用消息流式傳輸,它也適用於小文件,但與較舊的版本一樣會失敗。我懷疑這個錯誤在我的配置文件中,因爲svcutil.exe生成的配置文件沒有提供關於流式處理的任何信息。 這是我的客戶的app.config:WCF Streaming無法傳輸大文件

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
<system.serviceModel> 
    <bindings> 
     <wsHttpBinding> 
      <binding name="WSHttpBinding_IDocPublisher" closeTimeout="00:01:00" 
       openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" 
       bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" 
       maxBufferPoolSize="200000000" maxReceivedMessageSize="200000000" 
       messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" 
       allowCookies="false"> 
       <readerQuotas maxDepth="200000000" maxStringContentLength="200000000" maxArrayLength="200000000" 
        maxBytesPerRead="200000000" maxNameTableCharCount="200000000" /> 
       <reliableSession ordered="true" inactivityTimeout="00:10:00" 
        enabled="false" /> 
       <security mode="Message"> 
        <transport clientCredentialType="Windows" proxyCredentialType="None" 
         realm="" /> 
        <message clientCredentialType="Windows" negotiateServiceCredential="true" 
         algorithmSuite="Default" /> 
       </security> 
      </binding> 
     </wsHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="http://localhost:8000/ServiceModelSamples/docPublisherWebService/docPublisher" 
      binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IDocPublisher" 
      contract="IDocPublisher" name="WSHttpBinding_IDocPublisher"> 
      <identity> 
       <userPrincipalName value="Emil-PC\Emil" /> 
      </identity> 
     </endpoint> 
    </client> 
</system.serviceModel> 
</configuration> 

這是服務器的app.config

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
<system.serviceModel> 
<behaviors> 
    <serviceBehaviors> 
    <behavior name="serviceBehavior"> 
     <serviceMetadata httpGetEnabled="true"/> 
     <serviceDebug includeExceptionDetailInFaults="true" 
          httpHelpPageEnabled="true" /> 
     <dataContractSerializer maxItemsInObjectGraph="2147483647"/> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 
<services> 
    <service behaviorConfiguration="serviceBehavior" 
       name="DocPublisher"> 
    <endpoint address="http://localhost:8000/ServiceModelSamples/docPublisherWebService" 
       name="basicHttpStream" 
       binding="basicHttpBinding" 
       bindingConfiguration="httpLargeMessageStream" 
       contract="IDocPublisher" /> 
    <endpoint address="mex" 
        binding="mexHttpBinding" 
        contract="IMetadataExchange"/> 
    </service> 
</services> 
<bindings> 
    <basicHttpBinding> 
    <binding name="httpLargeMessageStream" 
       maxReceivedMessageSize="200000000" 
       maxBufferSize="200000000" 
       transferMode="Streamed" 
       messageEncoding="Mtom" /> 
    </basicHttpBinding> 
</bindings> 
</system.serviceModel> 
</configuration> 

回答

1

試圖增加在客戶端發送超時和讀者的配額,在服務器端設置緩衝區的大小。

+0

我無法在服務器上設置bufferSize,只是maxBufferSize。我嘗試了你所建議的改變,但他們沒有奏效。我已經用新值更新了我的代碼。 – 2013-03-14 15:23:23

1

原來的配置文件不是真正的問題,問題是服務器app.config從來沒有使用過,因爲msdn教程不使用app.config,而是在主要方法中創建端點。

+0

你能否詳細說一下Emil?如何更改即時創建的端點? – DevDave 2013-05-24 14:57:30