Note that there are some explanatory texts on larger screens.

plurals
  1. POuploading a file with WCF REST Services
    text
    copied!<p>I am new to WCF and Rest services, and tried to do some implementation from posts I found on the web, but I am still getting some problems. </p> <p>So let me explain my scenario.</p> <p>I have a WPF application, and in it I have a feedback form, which the client can fill up, attach some screenshots, and send it. Now my idea was to gather all this info inside an XML file, which I am already doing successfully, and then uploading this XML file on my server in a particular folder.</p> <p>Now as I understand it, the client app has to have a POST method to post the stream to the server, and then I should have an aspx page on the server to decode back the stream I get from the POST, and formulate my XML file, and then save it inside the folder, correct me if I'm wrong.</p> <p>At the moment I have implemented the code on the client as follows :-</p> <pre><code> public static void UploadFile() { serverPath = "http://localhost:3402/GetResponse.aspx"; filePath = "C:\\Testing\\UploadFile\\UploadFile\\asd_asd_Feedback.xml"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(serverPath); //request.MediaType = "text/xml"; request.ContentType = "text/xml"; //request.Method = "POST"; request.Method = "POST"; //request.ContentLength = contentLength; //request.ContentType = "application/x-www-form-urlencoded"; using (FileStream fileStream = File.OpenRead(filePath)) using (Stream requestStream = request.GetRequestStream()) { int bufferSize = 1024; byte[] buffer = new byte[bufferSize]; int byteCount = 0; while ((byteCount = fileStream.Read(buffer, 0, bufferSize)) &gt; 0) { requestStream.Write(buffer, 0, byteCount); } } string result = String.Empty; try { using (WebResponse response = request.GetResponse()) using (StreamReader reader = new StreamReader(response.GetResponseStream())) { result = reader.ReadToEnd(); } } catch (Exception exc) { } if (result == "OK") { } else { // error... } } </code></pre> <p>Now how can I pass the requestStream to the GetResponse.aspx page? And is this the correct way to go?</p> <p>Thanks for your help and time</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload