I'm attempting to write a .NET 2.0 web service to upload a file using a specific user ID and Password.
I would like to avoid using the ASPNET machine account for security issues.
Here is my exact code snipet:
My.Computer.Network.UploadFile("C:\sample.log", "http://localhost:3477/wsFileUpload/Uploads", "testuser", "testuser11")
I'm receiving the following WebException error:
The remote server returned an error: (405) Method Not Allowed
Further error trapping reveals: Status=ProtocolError
Sometimes I am receiving:
The underlying connection was closed: An unexpected error occurred on a receive. Status=ReceiveFailure
I am attempting to run this on my local PC.
VWD 2005 Express created a \WebSite1 and I added an "Uploads" folder.
The name of the web service is "wsFileUpload".
I am testing this web service in the development environment.
I created the user "test" on my PC and set it with all-access to the "Uploads" folder.
I also shared the "Uploads" folder.
I tried substituting my login info and ommitting the login info.
As far as web.config:
<authentication mode="Windows"/>
Nothing else exotic.
I am assuming it is a permission error - I hope I am not missing something basic
Thanks!

Errors using the UploadFile method
eliewadi
Thanks for your reply Karthikeya,
In IIS on my XP PC, how would I do that
Do I also need to add the specific user account to the security tab in the file system as well
-Dave
LastBoyScout
If you are getting a 405, then it means that the page on the server was not configured to receive this kind of content. In that case, you have to change the server to accept HTTP file uploads through POST.
Hope this helps you...
MattyP
Karthikeya,
I have done what you said and now I am getting:
(401) Unauthorized
I added the following elements to web.config:
- <
authentication mode="Windows" />In my Web Service application I changed the line from:
My
.Computer.Network.UploadFile(FileName, HostPath, "<domain\user", "pw")to:
My
.Computer.Network.UploadFile(FileName, HostPath)This does not change the error indicated above. Any other ideas
-Dave
clint 2
Technically, My.Application.Computer.Network.UploadFile() sends a multipart/form-data POST request, similar to a HTML file input element.
Your code doesn't work because you upload your file to a directory, not some web application component like a HttpHandler (unless some clever reverse proxying maps http://localhost:3477/wsFileUpload/Uploads to such a component
).
If all you want to do is write a file at a specific URL, you have to use System.Net.WebClient and send a PUT request. Both WebClient.UploadFile(uri, fileName, "PUT") and
WebClient.OpenWrite(uri, "PUT") will do the trick.
Note that the uri parameter in this case must include the actual file name, i.e. http://localhost:3477/wsFileUpload/Uploads/SomeFile.txt.
On the server side, you need to grant write access to whichever path you want to allow uploading files to. This applies to both the virtual directory's settings in IIS (to allow PUTs) and the physical directory's access control lists (the IIS process identity must have write access for each upload directory).
Regarding file uploads using Web Services: If all you need is a file upload capability, it's probably not the best idea. An ASP.NET HttpHandler is a much more lightweight solution, and since it consumes plain old HTTP requests, it interoperates with clients on every platform that speaks HTTP.
EnterBS
Dave,
Check the permissions for the folder
c:\inetpub\wwwroot\<upload folder>
Allow Modify permissions for users
have Integrated Authentication checked and Anonymous unchecked
astrocrep
Maybe I should be asking my question a different way...
I want to create a Web Service to upload a file. Is this a bad idea
-Dave
Krenshau
Jorg,
Thank you very much for taking the time to completely explain the solution and my options.
This was extremely helpful!
Thank you!
-Dave