2013-02-26 45 views
1

我想通過一個BMP文件作爲WCF服務中的參數。當BMP文件的大小爲350kb時,我收到一個錯誤。當我傳遞一個10-20 kb的小文件時,它可以完美運行。在wcf服務中傳遞bmp文件/圖像作爲參數

The remote server returned an unexpected response: (413) Request Entity Too Large. 

[OperationContract] 
byte[] ConvertData(Bitmap bmp); 

我曾嘗試與改變IIS設置以下鏈接來解決這個問題:http://blogs.msdn.com/b/jiruss/archive/2007/04/13/http-413-request-entity-too-large-can-t-upload-large-files-using-iis6.aspx但沒有運氣

我的服務器的web.config是

<system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
    <httpRuntime executionTimeout="240000"/>  
</system.web> 

<system.serviceModel> 
    <bindings> 
     <wsHttpBinding> 
      <binding name="BasicHttpBinding_IService1" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" hostNameComparisonMode="StrongWildcard" maxReceivedMessageSize="2147483647"> 
       <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647"/> 
      </binding> 
     </wsHttpBinding> 
    </bindings> 
    <services> 
     <service name="ReDrawImgService.Service1"> 
      <endpoint address="" binding="wsHttpBinding" bindingConfiguration="" contract="ReDrawImgService.IService1"/> 
     </service> 
    </services> 

    <behaviors> 
     <serviceBehaviors> 
      <behavior> 
       <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> 
       <serviceMetadata httpGetEnabled="true"/> 
       <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> 
       <serviceDebug includeExceptionDetailInFaults="false"/> 

      </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
</system.serviceModel> 

<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
</system.webServer> 

我的客戶的Web.Config是

<system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
    <httpRuntime executionTimeout="240000"/> 

</system.web> 

<system.serviceModel> 
    <bindings> 
     <wsHttpBinding> 
      <binding name="BasicHttpBinding_IService1" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" hostNameComparisonMode="StrongWildcard" maxReceivedMessageSize="2147483647"> 
       <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647"/> 
      </binding> 
     </wsHttpBinding> 
    </bindings> 
    <services> 
     <service name="ReDrawImgService.Service1"> 
      <endpoint address="" binding="wsHttpBinding" bindingConfiguration="" contract="ReDrawImgService.IService1"/> 
     </service> 
    </services> 

    <client> 
     <endpoint address="http://localhost:8012/Service1.svc" binding="wsHttpBinding" 
      bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceClient.IService1" 
      name="BasicHttpBinding_IService1" /> 
    </client> 
</system.serviceModel> 

回答

1

在您的readerQuotas上,嘗試將maxStringContentLength設置爲214748364 7以及,並確保此配置設置在兩端

所以服務器和客戶端都需要有這些值。如果客戶端被允許發送大文件,如果服務器無論如何都會拒絕它,這沒有任何幫助。

什麼是maxArrayLength在WCF服務器應用程序的價值

+0

HI您的回覆我已經在我的兩個CONFIGS改變maxStringContentLength到2147483647,但仍得到相同的錯誤
和的MaxArrayLength是服務器和客戶端在同一謝謝 – 2013-02-26 08:35:55

+0

當你正在調試這個時,你會得到比你的文章中給出的更多細節。通常,當這種情況失敗時,異常將指向什麼是錯誤的,例如,內容比maxStringContentLength長。 – 2013-02-26 08:39:58

+0

我已經通過一個bmp文件作爲參數,該bmp文件的大小是350 kb 當我通過一個10-20 kb的小文件,它運行完美,但給350 kb文件 – 2013-02-26 08:44:29