I would like my webservice to be able to take a username and a binary file parameter in the same call to it. Is this possible?
I thought I could use WebClient.Credentials and set a username that way, but it doesnt seem to be working
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The simplest way would be to turn your binary data into a base64 string. The string can be transmitted by passing it as a parameter or inside an XML string.
Web Service Method:
Now depending on the size files, this will incur a performance loss, but not a substantial one.
To convert a byte array to base64 string:
I will choose this method over WebClient.FileUpload() because I have more control and more options. Rather than just post to a page, I can send additional information up with this file, usernames, passwords etc. Especially if I put them all into a neat XML File.
or
where data could be:
You can choose to keep the file as a byte array, and just pass that, but I’m always a fan of using XML in webservices, so including my file inside an XML snippet (easier to log and record SOAP information).
WebClient.FileUpload method.
You will want to use cookies here. You will need to somehow authenticate with the server who you are (if you go this route) or at least have a UserName cookie the server will understand.
When you send your file, make sure you have the appropriate cookie going along with your file so the server knows what to do.
An example : http://www.codeproject.com/KB/cs/uploadfileex.aspx