2011-10-04 78 views
0

我有一個塞納里奧在那裏我有使用WCF服務,我是能夠成功地做,如果上載內容的大小小於1MB,但如果上載內容的大小大於1MB,蔭得到這樣的錯誤上傳一些DATASWCF綁定中的最大緩衝區大小是多少?

錯誤消息: - 在接收到 HTTP響應

發生錯誤的 「http://本地主機/ ABC /管理/服務/包」。由於服務端點綁定不使用HTTP協議,因此這可能是 。這個 也可能是由於HTTP請求上下文被服務器中止(可能是由於服務關閉)。有關更多詳細信息,請參閱服務器日誌 。

我認爲它的一個錯誤是關於我的緩衝區大小設置在我的綁定app.config。

我的app.config文件客戶端設置如下所示。

<system.serviceModel> 
    <client> 
     <endpoint address="http://localhost/abc/Services/Package" 
     binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_PackageService" 
     contract="PackageService.PackageService" name="BasicHttpBinding_PackageService" /> 
    </client> 
    <services> 
     <!-- This section is optional with the new configuration model 
      introduced in .NET Framework 4. --> 
     <service name="ServiceContracts.SearchServiceContract" 
       behaviorConfiguration="SearchServiceBehavior"> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://localhost:8080/xyz/SearchService"/> 
      </baseAddresses> 
     </host> 
     <!-- this endpoint is exposed at the base address provided by host: http://localhost:8080/xyz/SearchService --> 
     <endpoint address="" 
        binding="wsHttpBinding" 
        bindingConfiguration="NoSecurityBinding" 
        contract="ServiceContracts.ISearchServiceContract" /> 
     <!-- the mex endpoint is exposed at http://localhost:8080/xyz/SearchService/mex --> 
     <endpoint address="mex" 
        binding="mexHttpBinding" 
        contract="IMetadataExchange" /> 
     </service> 
     <service name="ServiceContracts.PackageServiceContract" 
       behaviorConfiguration="PackageServiceBehavior"> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://localhost:8080/xyz/PackageService"/> 
      </baseAddresses> 
     </host> 
     <!-- this endpoint is exposed at the base address provided by host: http://localhost:8080/xyz/PackageService --> 
     <endpoint address="" 
        binding="wsHttpBinding" 
        bindingConfiguration="NoSecurityBinding" 
        contract="ServiceContracts.IPackageServiceContract" /> 
     <!-- the mex endpoint is exposed at http://localhost:8080/xyz/PackageService/mex --> 
     <endpoint address="mex" 
        binding="mexHttpBinding" 
        contract="IMetadataExchange" /> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="SearchServiceBehavior"> 
      <serviceMetadata httpGetEnabled="true"/> 
      <serviceDebug includeExceptionDetailInFaults="true"/> 
      <dataContractSerializer maxItemsInObjectGraph="2147483646"/> 
     </behavior> 
     <behavior name="PackageServiceBehavior"> 
      <serviceMetadata httpGetEnabled="true"/> 
      <serviceDebug includeExceptionDetailInFaults="true"/> 
      <dataContractSerializer maxItemsInObjectGraph="2147483646"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <bindings> 
     <basicHttpBinding> 
     <binding name="BasicHttpBinding_PackageService" closeTimeout="00:01:00" 
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
      allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
      maxBufferSize="268435456" maxBufferPoolSize="268435456" maxReceivedMessageSize="268435456" 
      messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" 
      useDefaultWebProxy="true"> 
      <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" 
      maxBytesPerRead="268435456" maxNameTableCharCount="268435456" /> 
      <security mode="None"> 
      <transport clientCredentialType="None" proxyCredentialType="None" 
       realm="" /> 
      <message clientCredentialType="UserName" algorithmSuite="Default" /> 
      </security> 
     </binding> 
     </basicHttpBinding> 
     <wsHttpBinding> 
     <binding name="NoSecurityBinding"> 
      <security mode="None"> 
      <transport clientCredentialType="None" /> 
      <message establishSecurityContext="false" /> 
      </security> 
     </binding> 
     </wsHttpBinding> 
    </bindings> 
    </system.serviceModel> 

有誰可以知道這個請求的解決方法嗎?我的上傳大小可以達到2GB大小。那麼,我必須給出的確切buffersize或maxReceivedMessageSize或maxStringContentLength是什麼?

回答

2

OMG。當MS引入WCF時,他們應該真的提到,它不是數據上傳/下載技術,或者至少不是直接沒有額外的編碼。

你的服務是可怕的和2GB將最有可能無論如何也因爲它使用緩衝傳輸和普通文本的編碼工作。這意味着每個2GB將首先從磁盤加載到編碼爲Base64(+ 33%大小)的客戶端計算機的內存中。存儲到單個SOAP消息並傳遞到服務器,在該服務器中必須將整個消息加載到解碼和處理的內存中。任何網絡問題和整個信息都消失了。任何超時和整個消息都消失了。順便說一句。您的MaxReceivedMessageSize配置爲260MB =讀取260MB後,該服務將拋出錯誤的請求。

同時運行這種上傳並且您的服務器已經死機。服務器將被打開拒絕服務附加儘可能多。

要診斷在服務器端你的錯誤使用WCF tracing。瞭解如何傳輸大消息,請閱讀this article。它將幫助您定義性能更好的服務,但它仍然相當不可靠。最好的方法是在多個調用中使用一些分塊並傳輸大數據集,方法是在客戶端分解它們並將它們重新組合到服務器上。爲了提高可靠性並從故障中恢復,客戶端應該能夠從失敗的塊中繼續,而不是再次傳輸整個數據集。

有其它特徵,以考慮像壓縮,以減少傳送的數據和CRC的大小來驗證傳輸的數據不被傳輸格式錯誤。

恕我直言,這可以更好,更容易實施沒有WCF直接使用HttpListener或通用ASP.NET處理程序和HTTP分塊傳輸和範圍標題。