Uploading file attachments to a web service?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view

Uploading file attachments to a web service?

Jon G
I have one application that is using NeatUpload as a web page and it's working perfectly.  We have another application that runs as a web service and takes in files as DIME attachments.  I would like to upgrade it to use NeatUpload so that it can handle larger files. 

The web service allows multiple DIME attachments to come in using code similar to this:

                Dim iByte as Integer
                Dim fs As FileStream = File.Create(tempSaveFileDirectory & "\" & filename)

                Do While iByte <> -1
                    If iByte = -1 Then
                        Exit Do
                    End If

I have added the UploadHttpModule lines in the web.config. 

        <add name="UploadHttpModule" type="Brettle.Web.NeatUpload.UploadHttpModule, Brettle.Web.NeatUpload" />


<add key="NeatUpload.MaxNormalRequestLength" value="8192" />

I have set up the global.asax.vb with these lines:

Imports log4net
Imports log4net.Config

<Assembly: log4net.Config.XmlConfigurator(ConfigFile:="log4net.config", Watch:=True)>

and in application start:

        log.Info("Application Initialized")

The /NeatUpload directory is copied over

It seems to compile and work fine with small files, but when I attempt to send over a large file I get this error:

The request failed with HTTP status 413: Request Entity Too Large.

That happens on the line in my test page used to call the web service on the line where the call is made. 

In my test page that I use to call the web service I have added a line to increase the file size limit of the outgoing file in the web.config.

<httpRuntime maxRequestLength="100000" executionTimeout="360" useFullyQualifiedRedirectUrl="true" />

The file it fails on is about 12mb.  Which it seems like would be within the limit.  I am testing this locally with both applications on the same computer.  Does anyone have an idea of what I could be doing wrong?

Reply | Threaded
Open this post in threaded view

Re: Uploading file attachments to a web service?

Jon G
I just noticed that I missed a spot in my web.config.  You can actually see it in that last message I posted.  The line where it says

<add key="NeatUpload.MaxNormalRequestLength" value="8192" />

the value is now 40000.

Which leads me to the next error message:

There was an exception running the extensions specified in the config file. --> Maximum request length exceeded.

Now, does anyone have an idea of what could be causing that?  It seems to be something to do with the test page site sending a message to the web service that is too large, but I don't know where to go to fix it, or what limit needs to be increased.
Reply | Threaded
Open this post in threaded view

Re: Uploading file attachments to a web service?

Dean Brettle
The error you are currently getting is probably because the file being sent to the web service is larger than the value specified in the NeatUpload.MaxNormalRequestLength setting of the web service's Web.config file. The request length settings in ASP.NET and NeatUpload refer to the size of incoming requests not outgoing requests.

Having said that, NeatUpload isn't going to help you with the web service because it only streams files uploaded via an InputFile control on a web form.  You could try to hack the code to make it work for DIME attachments but my sense is that it would not be a small task.  Alternatively, you could use .NET 2.0 (which automatically streams large requests to disk) for the web service since it doesn't make sense to have a progress bar there.  So in the web service Web.config I'd remove the NeatUpload stuff and just increase maxRequestLength in the httpRuntime element. 

NeatUpload can help with the upload from the browser to the test page assuming you are using an InputFile there.  If the test page or something like it is going to visible to your customers and you want the progress bar to indicate the percent actually sent to web service, you might be able to use the latest development snapshot and implement an UploadStorageProvider which streams the upload directly to the web service.

Hope that helps,