none
Unable to transfer large file (binary) using WCF from Web Application

    Question

  • Hi,

    I have found similar topics in this very forum and also online, but none of them could give me a solution or give an explanation about where I am going wrong. All the solutions point to changing the readerQuota size or increasing the other attributes of the config settings.

    It will be of great help if someone could point out my mistakes and I am facing my deadlines around the corner. I have a web application which has uses the WCF service to upload a file on to the DataBase. I am streaming the file in Byte Array and passing it over the function. Both service and the application will be hosted on IIS. Please the code snippet which calls the WCF Service function : CreateAttachments

    Dim fInfo As New System.IO.FileInfo(dtAttachments.Rows(iCounter)("File Location").ToString())
    Dim numBytes As Long = fInfo.Length
    Dim fStream As New System.IO.FileStream(dtAttachments.Rows(iCounter)("File Location").ToString(), IO.FileMode.Open, IO.FileAccess.Read)
    Dim br As New System.IO.BinaryReader(fStream)
    Dim data As Byte() = br.ReadBytes(CInt(numBytes))
    fStream.Close()
    iStatus = proxy.CreateAttachements(iTicketID, dtAttachments.Rows(iCounter)("File Name").ToString(), data)

    I am getting the following error on executing the final statement of the code shown above:

    "The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation 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".


    Here is the WCF Service Config File.

    <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="HttpBinding_MTOM" messageEncoding="Mtom" transferMode="Streamed" maxBufferSize="10485760" maxReceivedMessageSize="67108864">
         <security mode="None">
           <transport clientCredentialType="None" />
         </security>
        </binding>
      </basicHttpBinding>

    </bindings>
    <services>
    <service name="XXXDataLayer.DataLayerService" behaviorConfiguration="XXXDataLayer.Service1Behavior">
     <endpoint address="" binding="basicHttpBinding" bindingConfiguration="HttpBinding_MTOM" contract="XXXDataLayer.IXXXDataLayer" />
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    </service>

    </services>
     <behaviors>
       <serviceBehaviors>
         <behavior name="XXXDataLayer.Service1Behavior">
         <serviceMetadata httpGetEnabled="True" />
         <serviceDebug includeExceptionDetailInFaults="True" />
         </behavior>
       </serviceBehaviors>
     </behaviors>
    </system.serviceModel>

    <httpRuntime maxRequestLength="2097151" />


    And here is the Web Application Config file which consumes the WCF Service.

    <system.serviceModel>
    <bindings>
    <basicHttpBinding>
    <binding name="BasicHttpBinding_IXXXDataLayer"
    maxBufferSize="10485760" maxBufferPoolSize="67108864" maxReceivedMessageSize="67108864"
    messageEncoding="Mtom" transferMode="Streamed">
    <readerQuotas maxDepth="64" maxStringContentLength="214748364" maxArrayLength="214748364"
    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
    <security mode="None">
    <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
    </security>
    </binding>
    </basicHttpBinding>
    </bindings>
    <client>
    <endpoint address="http://XXX/XXXWebHelpRequestRemoting/DataLayerService.svc"
    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IXXXDataLayer"
    contract="XXXDataLayer.IXXXDataLayer" name="BasicHttpBinding_IXXXDataLayer" />
    </client>
    </system.serviceModel>

    I have run this application in both visual studio and also from a website hosted on IIS. In both cases I seem to have problems. Kindly let me know the mistake that I have made or if you have any alternate solution for the given situation.

    Thanks and regards,

    Sai

    Wednesday, August 12, 2009 5:22 AM

Answers

All replies

  • Can you try adding the <readerQuotas> section to the binding on the service file as well?
    Wednesday, August 12, 2009 6:10 AM
  • Carlos,


    That worked! Thanks a ton. I noticed that if I delete the service reference and add it back, the changes that I have made vanishes. Is there any way to not allow that???

    Thanks again.

    Sai

    Wednesday, August 12, 2009 5:03 PM
  • Great that it worked!
    About the service reference, not really, once you update / delete+add the service reference, it will download the metadata again from the server to recreate the config file. A couple of options is to save the original app.config, then replace it after updating the service reference, or you can use the svcutil.exe tool (http://msdn.microsoft.com/en-us/library/aa347733.aspx), in which you can specify the /noconfig option (so it won't generate config).
    Wednesday, August 12, 2009 5:09 PM