Question

want to save a file in database as binary data using WCF. Client is ASP.NET C#. i have using the following code and able to send less then 100KB.

Client config file's code is

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="basicHttpBinding_IService" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
          allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
          maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"
          textEncoding="utf-8" transferMode="StreamedResponse" useDefaultWebProxy="true"
          messageEncoding="Mtom">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
           maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"
              realm="">
              <extendedProtectionPolicy policyEnforcement="Never" />
            </transport>
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
        <binding name="BasicHttpBinding_IWITSService" />

      </basicHttpBinding>
    </bindings>

    <behaviors>
      <endpointBehaviors>
        <behavior name="debuggingBehaviour">

          <dataContractSerializer maxItemsInObjectGraph="2147483647" />

        </behavior>
      </endpointBehaviors>
    </behaviors>
    <client>
      <endpoint address="http://localhost:4175/WITSWCFService.svc"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IWITSService"
        contract="MyService.IWITSService" name="BasicHttpBinding_IWITSService" />
    </client>
  </system.serviceModel>

AND Service Config file's code is given below

<system.web>
    <compilation debug="true" />
    <httpRuntime executionTimeout="4800" maxRequestLength="2147483647" />


  </system.web>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="basicHttpEndpointBinding" closeTimeout="01:01:00"
          openTimeout="01:01:00" receiveTimeout="01:10:00" sendTimeout="01:01:00"
          allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
          maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
          messageEncoding="Mtom" textEncoding="utf-8" transferMode="StreamedRequest"
          useDefaultWebProxy="true">
          <readerQuotas  maxDepth="64"  maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="4096"  maxNameTableCharCount="16384"/>
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"
              realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default"  />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service name="WITSService.WITSService"  >

        <endpoint bindingConfiguration="basicHttpEndpointBinding" address="basic" binding="basicHttpBinding" contract="WITSService.WITSService" />


      </service>
    </services>


    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="myEndPointBehavior">
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
        </behavior>
      </endpointBehaviors>
    </behaviors>

    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

When i upload 300 kb file i got this error

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

can any one help me where i made mistake.. Thanks in Advance

Was it helpful?

Solution

I have solved this issue by using this Code in my Service.config file.

<services>
      <service name="Service.IService">
        <clear />
        <endpoint binding="basicHttpBinding" contract="Service.IService" />
      </service>
    </services>
    <bindings>
      <basicHttpBinding>
        <binding maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="32" maxStringContentLength="2147483647"
            maxArrayLength="16348" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
        </binding>
      </basicHttpBinding>
      <webHttpBinding>
        <binding maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" />
      </webHttpBinding>
    </bindings>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top