Get Data from HTTP POST Request RRS feed

  • Question

  • How do i get the data inside an HTTP POST request , that is received in my WCF Service?

    i send the data from another service using HTTP POST:

    string ReportText = "Hello world"; 
    ASCIIEncoding encoding = new ASCIIEncoding(); 
    byte[] data = encoding.GetBytes(ReportText); // Prepare web request... 
    String serverURL = ConfigurationManager.AppSettings["REPORT"]; 
    HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(serverURL); 
    myRequest.Method = "POST"; 
    myRequest.ContentType = "application/x-www-form-urlencoded"; 
    myRequest.ContentLength = data.Length; 
    Stream newStream = myRequest.GetRequestStream(); // Send the data. 
    newStream.Write(data, 0, data.Length); 

    but when i receive the POST request in the WCF, how do i extract the data from the HTTP POST request ?

    Sunday, March 27, 2011 8:59 AM


  • Hello,

    You should use the REST support of WCF to implement this. You have to create a service that uses the webHttpBinding and you should mark the method that needs to accepts the string with the WebInvoke attribute.

    public interface IMyService
     void ProcessReport(string value);


    • Proposed as answer by Pieter De Rycke Thursday, March 31, 2011 10:01 AM
    • Marked as answer by Yi-Lun Luo Friday, April 1, 2011 8:59 AM
    Sunday, March 27, 2011 2:22 PM