473,657 Members | 2,449 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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=multipa rt/form-data, the action is the webservice method, i.e.
action=webservi ce/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 8289
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.Cur rent;
// file collection of uploaded files in the http context
HttpFileCollect ion Files = theContext.Requ est.Files;
// if something there then read the posted upload
if(1==Files.Cou nt & 1<Files[0].ContentLength)
{
theReturn += Files[0].ContentLength;
theReturn += Files[0].ContentType;
using(StreamRea der srFiledata = new StreamReader(Fi les[0].InputStream))
{
sbOutput.Append (srFiledata.Rea dToEnd());
}
// double check to make sure this is valid upload
// to do code
theReturn+=sbOu tput.ToString() ;
// now pick up the additional form fields

theReturn += theContext.Requ est.Form["dbConnecti on"];
//theReturn += theContext.Requ est.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;
}

"Scanner200 1" <je************ @hotmail.com> wrote in message
news:O1******** ******@TK2MSFTN GP09.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=multipa rt/form-data, the action is the webservice method, i.e.
action=webservi ce/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
4247
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 the rate for a certain size, "from:" address, "To:" address and delivery service speed. The examples they showed used a HTML "Text Area" and a HTTP post statement to send the request however I need to use input from an input box and then insert...
12
2654
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 be posted behind the scenes to the provider's URL (e.g., http://www.surveyprocessingprovider.com/srvy1?field1=response1&field2=response2) 2. the user has to be redirected to thankyou.aspx.
2
12548
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 <form action="display.aspx" method="post" target="_blank"> will submit the form data and open display.asp in a new browser
8
5074
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 to asp.net vb code? !--<FORM ACTION="/test/test.php" METHOD=POST>--> <form action="https://multipay.net/transaction/mpmain.php" method="post"> ....
3
6911
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 as per RFC 2617 (http://www.faqs.org/rfcs/rfc2617.html). My attempts to authenticate are failing. The server requires the header to be present with the request. For security reasons, it will not reply in any way if the header is not present. ...
1
31521
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 application that uses Macromedia’s flash.net.FileReference class. The FileReference class behaves like a standard HTML form with the file input tag. I know there are other options for submitting files through Web Services, but we’re not able...
6
5097
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 how to encode a file on a POST to the same web service. The definition requires a base64binary encoded file, which I have tried. The form is also using a mutlipart/form-data enctype, but I either get a 500 error or 'Request format is invalid'. ...
56
7214
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 website. The issue is that I need to gauge whether a user has any items in their basket to decide which page I redirect them too. I could
8
2393
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, modification of a database or subscription to a service), the method should be POST. (http://www.cs.tut.fi/~jkorpela/ forms/methods.html). However, later I did not find any convinced arguments why it should
0
8826
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8503
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7330
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4155
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4306
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1615
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.