title: How to Receive Multipart Form Data on WCF Service. I have uploaded it using the phone gap file transfer plugin upload function
body: <p>How can I receive multipart form data in a WCF Service? I have uploaded it using the phone gap file transfer plugin upload function.</p>
  
  <p>Below are the two functions that I'm trying to call:</p>
  
  <pre><code>    ///&lt;summary&gt;
      ///Method for file upload
      ///&lt;/summary&gt;
      [OperationContract]
      [WebInvoke(
          Method = "POST",
          BodyStyle = WebMessageBodyStyle.Bare,
          UriTemplate = "Upload")]
      string Upload(Stream data);
  
  
      [OperationContract]
      [WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped, Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "UploadImage")]
     string UploadImage();
  
      // TODO: Add your service operations here
  </code></pre>
  
  <p>I successfully hit the UploadImage function but I don't know how to read a file from the uploaded data.</p>
  
  <p>When I try   </p>
  
  <pre><code>HttpPostedFile file = HttpContext.Current.Request.Files["recFile"];
  </code></pre>
  
  <p>I get the error:</p>
  
  <pre><code>    HttpContext.Current.Request.Files   'HttpContext.Current.Request.Files' threw an exception of type 'System.Web.HttpException'   System.Web.HttpFileCollection {System.Web.HttpException}
      base    {"This method or property is not supported after HttpRequest.GetBufferlessInputStream has been invoked."}   
  </code></pre>
  
  <p>This is my web.config  file:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;configuration&gt;
    &lt;system.web&gt;
      &lt;compilation debug="true" targetFramework="4.5" /&gt;
       &lt;customErrors mode="RemoteOnly"/&gt;
      &lt;caching&gt;
        &lt;outputCacheSettings&gt;
          &lt;outputCacheProfiles&gt;
            &lt;add name="CacheFor10Seconds" duration="10"
                 varyByParam="none" /&gt;
          &lt;/outputCacheProfiles&gt;
        &lt;/outputCacheSettings&gt;
      &lt;/caching&gt;
      &lt;httpRuntime maxRequestLength="2000000000"/&gt;
    &lt;/system.web&gt;
    &lt;appSettings&gt;
  
      &lt;add key="aspnet:UseTaskFriendlySynchronizationContext" value="false" /&gt;
    &lt;/appSettings&gt;
    &lt;system.serviceModel&gt;
      &lt;bindings&gt;
        &lt;webHttpBinding&gt;
              &lt;binding name="webHttpBindingWithJsonP"
                   crossDomainScriptAccessEnabled="true" maxBufferSize="2000000000"
                  maxReceivedMessageSize="2000000000"
                transferMode="Streamed"   /&gt;
        &lt;/webHttpBinding&gt;
      &lt;/bindings&gt;
      &lt;behaviors&gt;
  
        &lt;endpointBehaviors&gt;
          &lt;behavior name="webHttpBehavior"&gt;
            &lt;webHttp helpEnabled="true"/&gt;
          &lt;/behavior&gt;
        &lt;/endpointBehaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior&gt;
            &lt;serviceMetadata httpGetEnabled="true"  /&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
      &lt;/behaviors&gt;
      &lt;serviceHostingEnvironment aspNetCompatibilityEnabled="true"
          multipleSiteBindingsEnabled="true" /&gt;
      &lt;services&gt;
        &lt;service name="Service.Service1"&gt;
  
          &lt;endpoint name="mexHttpBinding"
                    address="mex"
                    binding="mexHttpBinding"
                    contract="IMetadataExchange"
                    /&gt;
          &lt;endpoint address="" behaviorConfiguration="webHttpBehavior"
              binding="webHttpBinding"
                    bindingConfiguration="webHttpBindingWithJsonP"
              contract="Service.IService1" /&gt;
  
        &lt;/service&gt;
      &lt;/services&gt;
    &lt;/system.serviceModel&gt;
    &lt;system.webServer&gt;
      &lt;modules runAllManagedModulesForAllRequests="true"/&gt;
      &lt;httpProtocol&gt;
        &lt;customHeaders&gt;
          &lt;add name="Access-Control-Allow-Origin" value="*" /&gt;
          &lt;add name="Access-Control-Allow-Headers" value="Content-Type" /&gt;
        &lt;/customHeaders&gt;
      &lt;/httpProtocol&gt;
    &lt;/system.webServer&gt;
  &lt;/configuration&gt;
  </code></pre>