This post is based on post File Upload from Silverlight using WCF. So please read it before proceeding with this post

Long back I wrote post on uploading a File from Silverlight to server location using WCF. I found my own post quiet useful. However, when I reread and implemented the code, I mentioned in the post, I found few discrepancies

  1. Code was unable to upload file with sizes in MB
  2. There was a bug in binding configuration

In this post, I am going to rectify above two bugs.

First modify basicHttpBinding as below,

image

Configure Endpoint as below,

image

So far everything is fine and if you run the code, you would able to upload a file maximum of the size 3MB. I tested and I was able to upload document file of size 2.75 MB.

Now question comes, what if we want to upload a file of the size around 10 MB?

For that we need to reconfigure the things in configuration file

  1. Configure service behavior maximum number of items to serialize or deserialize.
  2. Configure HTTP Request length limit.

You need to explicitly configure the behavior of service to the maximum number of items to serialize or deserialize. This can be configured either in code or in configuration file.

MaxItemsInObjectGraph property of DataContractSerilalizer determines number of items can be serizlized or deserizlized.

image

Http Request limit can be configured as below

image

After completing above changes configuration file at service would look like below,


<?xml version="1.0"?>

<configuration>

  <system.web>

    <compilation debug="true" targetFramework="4.0" />

    <httpRuntime maxRequestLength="10240" />

  </system.web>

  <system.serviceModel>

    <bindings>

      <basicHttpBinding>

        <binding name="ServicesBinding"

                 maxReceivedMessageSize="2147483647"

                 maxBufferSize="2147483647">

          <readerQuotas

                    maxArrayLength="2147483647"

                    maxBytesPerRead="2147483647"

                    maxDepth="2147483647"

                    maxNameTableCharCount="2147483647"

                    maxStringContentLength="2147483647" />

        </binding>

      </basicHttpBinding>

    </bindings>

    <services>

      <service name="ServiceData.Service1" behaviorConfiguration="ServiceData.Service1Behavior">

        <endpoint address="" binding="basicHttpBinding" contract="ServiceData.IService1" bindingConfiguration ="ServicesBinding" >

          <identity>

            <dns value="localhost"/>

          </identity>

        </endpoint>

        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>

      </service>

    </services>

    <behaviors>

      <serviceBehaviors>

        <behavior name ="ServiceData.Service1Behavior">

          <serviceMetadata httpGetEnabled="true"/>

          <serviceDebug includeExceptionDetailInFaults="false"/>

          <dataContractSerializer maxItemsInObjectGraph ="2147483647"/>

        </behavior>

      </serviceBehaviors>

    </behaviors>

    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

  </system.serviceModel>

 <system.webServer>

    <modules runAllManagedModulesForAllRequests="true"/>

  </system.webServer>

</configuration>

Now you should able to upload a large file as of size 10 MB from Silverlight client to the server location using WCF Smile


**************

Add to FacebookAdd to DiggAdd to Del.icio.usAdd to StumbleuponAdd to RedditAdd to BlinklistAdd to TwitterAdd to TechnoratiAdd to Yahoo BuzzAdd to Newsvine

Advertisements

5 thoughts on “Upload large file of size more than 5 MB from Silverlight to Server location using WCF

  1. I have achieved the same scenario by changing it to CustomBinding with Tranfermode “Streamed” http protocol.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s