Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
HI,
I have created WCF services which allow desktop based application to upload/download large file through wcf service.
The service is working working properly the way it should but the problem is that i can not upload large file from Desktop application. I am storing that uploaded file directly to the database using Byte[]

here is my web.config
----------------------------------
XML
<?xml version="1.0"?>
<configuration>
  <connectionStrings>
  </connectionStrings>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <httpRuntime maxRequestLength="2147483647"/>
  </system.web>
  <system.serviceModel>

      <bindings>

      <basicHttpBinding>

        <binding name="BasicHttpBinding_IFileHandlerDuplex" closeTimeout="01:10:00"
         openTimeout="01:10:00" receiveTimeout="01:10:00" sendTimeout="01:10:00"
         allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
         maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
         messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
         useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647"
           maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"
             realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings> 
    <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"/>
             <!--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="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>





can you tell what should i do to upload/download large to/file from database using WCF service ?
Posted
Updated 21-Mar-13 20:23pm
v2
Comments
bluesathish 22-Mar-13 6:09am    
do you got any errors while upload large files? if yes, what it is?
Kalpesh_Bhadra 25-Mar-13 1:16am    
the error is as follow

1>
The remote server returned an unexpected response: (400) Bad Request.


2>
The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:FileAttachment. The InnerException message was 'There was an error deserializing the object of type CAIS_BusinessObjects.CAIS_FileAttachmentBO. The maximum array length quota (16384) has been exceeded while reading XML data. This quota may be increased by changing the MaxArrayLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader. Line 1, position 27123.'. Please see InnerException for more details.
bluesathish 25-Mar-13 1:43am    
what kind of data you're uploading? whether it is a block of records to be inserted into the table or what?
Kalpesh_Bhadra 25-Mar-13 2:14am    
i have allowed user to upload any kind of file to the database.
generally it ll be type of images, documents or a zip type of files.
on the desktop application it allowing me to upload small sized images and document
bluesathish 25-Mar-13 2:47am    
I thought your parameters in webconfig are fine. Everything has some limits, if you upload beyond the limit of the acceptable size means how the system can able to handle that? so my point is better you try to compress your inputs if it thorws errors.

if it is working in a browser, it will work in an app as well. my guess is that you have to specify some parameteres like timeout, etc. to get it to work (in the desktop app!).
 
Share this answer
 
v2
Comments
Kalpesh_Bhadra 22-Mar-13 8:49am    
yes it working properly on browser but shows error on desktop application
and the error is as follow


i am passing an object of class which contains the following Fields

public long FileID;
public long ClientID;
public long AdvisorID;
public string Owner;
public string FileName;
public string FileMIME;
public byte[] FileStream;
//i want to restrict user not to upload file more than size of 100mb
public bool Is_Password;
public string Password;
public string FileType;
public string FileDesc;
public DateTime Created_On;




--------------
The remote server returned an unexpected response: (400) Bad Request.

-----------------

The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:FileAttachment. The InnerException message was 'There was an error deserializing the object of type CAIS_BusinessObjects.CAIS_FileAttachmentBO. The maximum array length quota (16384) has been exceeded while reading XML data. This quota may be increased by changing the MaxArrayLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader. Line 1, position 27123.'. Please see InnerException for more details.
here is my app.config file of the application

---------------------------------------------------
HTML
<configuration>
    <system.servicemodel>
        <bindings>
            <basichttpbinding>
                <binding name="Service1Soap" closetimeout="01:00:00" opentimeout="01:00:00">
                    receiveTimeout="01:00:00" sendTimeout="01:00:00" allowCookies="false"
                    bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
                    <readerquotas maxdepth="32" maxstringcontentlength="8192" maxarraylength="16384">
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="None">
                        <transport clientcredentialtype="None" proxycredentialtype="None">
                            realm="" />
                        <message clientcredentialtype="UserName" algorithmsuite="Default" />
                    </transport></security>
                </readerquotas></binding>
                <binding name="BasicHttpBinding_ICAIS__AdvisiorWebService" closetimeout="01:00:00">
                    openTimeout="01:00:00" receiveTimeout="01:00:00" sendTimeout="01:00:00"
                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
                    <readerquotas maxdepth="32" maxstringcontentlength="8192" maxarraylength="16384">
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="None">
                        <transport clientcredentialtype="None" proxycredentialtype="None">
                            realm="" />
                        <message clientcredentialtype="UserName" algorithmsuite="Default" />
                    </transport></security>
                </readerquotas></binding>
                <binding name="BasicHttpBinding_ICAIS__AdvisiorWebService1" closetimeout="01:00:00">
                    openTimeout="01:00:00" receiveTimeout="01:00:00" sendTimeout="01:00:00"
                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="11655360" maxBufferPoolSize="524288" maxReceivedMessageSize="11655360"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
                    <readerquotas maxdepth="32" maxstringcontentlength="1181920" maxarraylength="11163840">
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="None">
                        <transport clientcredentialtype="None" proxycredentialtype="None">
                            realm="" />
                        <message clientcredentialtype="UserName" algorithmsuite="Default" />
                    </transport></security>
                </readerquotas></binding>
                <binding name="BasicHttpBinding_ICAIS_ManagerWebService1" closetimeout="00:01:00">
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
                    <readerquotas maxdepth="32" maxstringcontentlength="8192" maxarraylength="16384">
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="None">
                        <transport clientcredentialtype="None" proxycredentialtype="None">
                            realm="" />
                        <message clientcredentialtype="UserName" algorithmsuite="Default" />
                    </transport></security>
                </readerquotas></binding>
                <binding name="BasicHttpBinding_ITransferService" closetimeout="00:01:00">
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
                    <readerquotas maxdepth="32" maxstringcontentlength="8192" maxarraylength="16384">
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="None">
                        <transport clientcredentialtype="None" proxycredentialtype="None">
                            realm="" />
                        <message clientcredentialtype="UserName" algorithmsuite="Default" />
                    </transport></security>
                </readerquotas></binding>
            </basichttpbinding>
        </bindings>
        <client>

</client></system.servicemodel></configuration>
 
Share this answer
 
Comments
Kalpesh_Bhadra 25-Mar-13 0:47am    
i can upload large file from browser but on desktop application it shows exceptions as followed,
please help me get over it


1>
The remote server returned an unexpected response: (400) Bad Request.


2>
The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:FileAttachment. The InnerException message was 'There was an error deserializing the object of type CAIS_BusinessObjects.CAIS_FileAttachmentBO. The maximum array length quota (16384) has been exceeded while reading XML data. This quota may be increased by changing the MaxArrayLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader. Line 1, position 27123.'. Please see InnerException for more details.
Quote:
Hi Kalpesh,
Your appconfig file has the restriction, change the below parameters as mentioned. And after changing write click your service reference and click Update Service Reference option.

XML
maxBufferSize="65536000" maxBufferPoolSize="524288000" maxReceivedMessageSize="65536000"  maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="8192" maxNameTableCharCount="2147483647"


Thanks and regards,
Bluesathish
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900