angela navarro
angela navarro

Reputation: 21

Cannot upload more than 64kb to WCF REST Service from client

I have created a WCF REST Service and have successfully created a function to upload a file from the client to the service.

The problem is, this only works when the file being sent is 64kb or less. How can I fix this problem.

web.config file:

<configuration>

<system.web>
    <compilation debug="true" targetFramework="4.0" />
    <httpRuntime maxRequestLength="2147483647"/>
</system.web>

<system.webServer>
  <security>
    <requestFiltering>
      <requestLimits maxAllowedContentLength="100000000"> </requestLimits>
    </requestFiltering>
  </security>
  <validation validateIntegratedModeConfiguration="false"/>
    <modules runAllManagedModulesForAllRequests="true">
        <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </modules>
</system.webServer>

<system.serviceModel>

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    <standardEndpoints>
        <webHttpEndpoint>
            <!-- 
        Configure the WCF REST service base address via the global.asax.cs file and the default endpoint 
        via the attributes on the <standardEndpoint> element below
    -->
            <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/>
        </webHttpEndpoint>
    </standardEndpoints>
</system.serviceModel>

and global.asax:

namespace WCFRESTService
{
public class Global : System.Web.HttpApplication
{

    protected void Application_Start(object sender, EventArgs e)
    {
        RegisterRoutes();
    }

    private void RegisterRoutes()
    {
        // Edit the base address of Service1 by replacing the "Service1" string below
        RouteTable.Routes.Add(new ServiceRoute("RO", new WebServiceHostFactory(), typeof(Service1)));
    }
}

}

Upvotes: 2

Views: 704

Answers (2)

Rajkumar
Rajkumar

Reputation: 121

After 3 days of my googling search finally i found the solution

In my solution, web.config i've added https code and etc. after that i have removed all the config and added this below code

<system.web>
    <compilation debug="true" targetFramework="4.5.2" />
    <httpRuntime targetFramework="4.5.2"/>
  </system.web>

  <system.serviceModel>
    <services>
      <service behaviorConfiguration="ServiceBehaviour" name="NativeAppServices.Service1">
        <endpoint address="" binding="webHttpBinding" bindingConfiguration="StreamedRequestWebBinding"  contract="NativeAppServices.IService1" behaviorConfiguration="webBehavior">
        </endpoint>
      </service>
    </services>

    <bindings>
      <webHttpBinding>
        <binding name="StreamedRequestWebBinding" closeTimeout="00:25:00"
          openTimeout="00:25:00" receiveTimeout="00:25:00" sendTimeout="00:25:00"
          bypassProxyOnLocal="true" hostNameComparisonMode="WeakWildcard"
          maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
          transferMode="StreamedRequest" useDefaultWebProxy="false">
          <readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" />
        </binding>
      </webHttpBinding>
    </bindings>

    <behaviors>
      <serviceBehaviors >
        <behavior name="ServiceBehaviour">
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="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>
      <endpointBehaviors>
        <behavior name="webBehavior">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>

    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https"/>
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"></serviceHostingEnvironment>
  </system.serviceModel>

  <system.webServer>
    <directoryBrowse enabled="true"/>
  </system.webServer>

Upvotes: 1

angela navarro
angela navarro

Reputation: 21

Figured it out. Had to add attributes "maxReceivedMessageSize" and "maxBufferSize" to the

Upvotes: 0

Related Questions