title: Need a web service for NIH
body: <p>My company is using an ipad app called NIH Toolbox. It collects information and when done you can upload the data to a web location via a web service. SO I created a rest web service in visual studio 2015, and it works for me but not the NIH toolbox software. The manual includes an example of a web service that can be used with their app but I can't figure out where to begin with the code they include.</p>
  
  <p><strong>Sample webservice to be used configuration reference:</strong>
  If Export to Web is enabled on the iPad, all of the data generated by this app will be immediately sent via a web service to the URL set by the user.
  Data export to web feature posts .csv files to a web location specified by the app user. Data export to web security is handled in the form of basic authentication. Web service should be set to accept basic authentication. Web service implementation should also acknowledge successful transfer of the file in the form of json object. </p>
  
  <ul>
  <li><p>Data upload webservice </p>
  
  <p>o Form action: POST </p>
  
  <p>o Form request parameters:
   
  upload: optional. Data are attached to this variable. </p>
  
  <p>o Form Response json object format:</p>
  
  <p>{ </p>
  
  <p>“error”:error_code, (error code of 0 indicates successfully transfer of file). 
    “message”:”message” (optional) </p>
  
  <p>}</p></li>
  </ul>
  
  <p><strong>Sample of web service implementation in .NET (c#):</strong></p>
  
  <pre><code>/***************** BASIC AUTHENTICATION */
  if (ctx.Request.HttpMethod == "OPTIONS")
  {
     ctx.Response.ContentType = "text";
     ctx.Response.ContentEncoding = Encoding.UTF8;
     ctx.Response.AppendHeader("Content-Length", "0");
     ctx.Response.AppendHeader("Connection", "keep-alive");
     ctx.Response.AppendHeader("Access-Control-Allow-Origin", "*");
     ctx.Response.AppendHeader("Access-Control-Allow-Headers", "Authorization, Origin, content-type, accept");
     ctx.Response.AppendHeader("Access-Control-Allow-Credentials", "true");
     ctx.Response.AppendHeader("Access-Control-Allow-Methods", "OPTIONS, GET, POST");
     return;
  }
  if (ctx.Request.Headers["Authorization"] == null)
  {
     ctx.Response.StatusCode = 401;
     ctx.Response.AppendHeader("WWW-Authenticate", "Basic");
     return;
  }
  
  //validate authentication
  if 
  (!Authenticate.ValidateRequest(ctx.Request.Headers["Authorization"].ToString()))
  {
       ctx.Response.StatusCode = 401;
       return;
  }
  
  //save file
       if (ctx.Request.HttpMethod.ToUpper() == "POST")
  {
        try
        {
           if (ctx.Request.Files.Count &gt; 0)
           {
              HttpPostedFile myFile = ctx.Request.Files[0];
              if (myFile != null &amp;&amp; myFile.ContentLength &gt; 0)
              {
                 Stream fileContents = myFile.InputStream;
                 string fileName = Path.GetFileName(myFile.FileName);
                string path = 
             Path.Combine(ctx.Server.MapPath("~/UploadedData"), fileName);
                 myFile.SaveAs(path);
                 ctx.Response.ContentType = "application/json";
                 ctx.Response.Write("{\"error\":\"0\"}");
                 return;
              }
         }
         else
         {
            ctx.Response.StatusCode = 1;
            return;
         }
    }
    catch (Exception e)
    {
        ctx.Response.StatusCode = 1;
        return;
    }
  }
  </code></pre>
  
  <p>I've just not spent a great deal of time working with web services like this. If some wonderful person could push me in the correct direction, I would be very thankful.</p>