473,395 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

post form data to web service

I am trying to receive form data posted from an html page to a web
service method. In other words, a web page posts data as
encrypt=multipart/form-data, the action is the webservice method, i.e.
action=webservice/methodname. The form includes the contents of an uploaded
file, i.e. a file browse button in the form.
I can perform similar actions taking in just string data and post it to
the web service and process the data. But I seem to be having a problem with
the uploaded file from the form.
Any suggestions on how to do this, or how to receive the data? I can not
modify the original html page that has the form, other than the url in the
action of the form.

Thanks,
J
Nov 23 '05 #1
1 8226
I figured it out, thought I would post some sample code in case anyone
else is looking:
FYI: The code needs work before being "production" ready. I do not
believe this will work for some types of files, such as images, because it
would need to be changed to a base64 binary read. But I do not have this
need, I needed to read in standard text files.

[WebMethod]
public string GetData()
{
string theReturn = "";
StringBuilder sbOutput = new StringBuilder();
try
{
// the constructor for the http context
HttpContext theContext = HttpContext.Current;
// file collection of uploaded files in the http context
HttpFileCollection Files = theContext.Request.Files;
// if something there then read the posted upload
if(1==Files.Count & 1<Files[0].ContentLength)
{
theReturn += Files[0].ContentLength;
theReturn += Files[0].ContentType;
using(StreamReader srFiledata = new StreamReader(Files[0].InputStream))
{
sbOutput.Append(srFiledata.ReadToEnd());
}
// double check to make sure this is valid upload
// to do code
theReturn+=sbOutput.ToString();
// now pick up the additional form fields

theReturn += theContext.Request.Form["dbConnection"];
//theReturn += theContext.Request.Form[2];
}
// here send back something to indicate that nothing was uploaded or it
is invalid
else
{
theReturn += "Nothing Uploaded";
}
}
catch(Exception ex1)
{
theReturn = ex1.Message;
}

return theReturn;
}

"Scanner2001" <je************@hotmail.com> wrote in message
news:O1**************@TK2MSFTNGP09.phx.gbl...
I am trying to receive form data posted from an html page to a web
service method. In other words, a web page posts data as
encrypt=multipart/form-data, the action is the webservice method, i.e.
action=webservice/methodname. The form includes the contents of an uploaded file, i.e. a file browse button in the form.
I can perform similar actions taking in just string data and post it to the web service and process the data. But I seem to be having a problem with the uploaded file from the form.
Any suggestions on how to do this, or how to receive the data? I can not modify the original html page that has the form, other than the url in the
action of the form.

Thanks,
J

Nov 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Geoff | last post by:
I have been asked to add postal rates to a web page shopping cart checkout procedure. After contacting the post office I discovered that they used XML to receive postal rate requests and send back...
12
by: Assaf | last post by:
Hi all, My client is using an online service provider that processes survey responses. After a user fills survey.aspx and presses the OK button, 2 things need to happen: 1. the data has to...
2
by: Matt | last post by:
When we submit the form data to another page, we usually do the following: <form action="display.aspx" method="post"> will submit the form data and open display.asp in the current browser ...
8
by: Gert | last post by:
Hi, I have a form (server side) because of the filling of variables through the application. But now I need to post it to an url on submit. My .HTML form looks like this, but how to translate it...
3
by: Patrick Fogarty | last post by:
I am programming what is to be a web service client that will use an HTTP-POST to request and retrieve data. The remote server (written in java for what it's worth) requires basic authentication...
1
by: John Wolff | last post by:
I’m trying to upload a file to a Web Service. I have to submit the file using a standard HTML form with the <input type=“file” /tag. Ultimately, we are submitting the file from a Flash 8...
6
by: Brybot | last post by:
I am trying to allow HTTP POST file uploads to my web service. Currently I have it working perfectly for a SOAP/XML request reading in a byte using MemoryStream/FileStream but I cannot figure out...
56
by: UKuser | last post by:
Hi, I'm not sure if this can be done as I've searched the web and this forum. I am using an online merchant provider and I must post certain variables to their webforms through a form on my...
8
by: Kurda Yon | last post by:
Hi, I have to decide which form-method I should use (GET or POST). I found the following recomendation: If the service associated with the processing of a form has side effects (for example,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.