Create and Consume RESTFul Service


  • Hi, I've already created my WCF and now I want to retrieve out the data that is inside the database using Restful Service. Can anyone help me? I tried on this code:

     void CallGetMethod()
            HttpWebResponse response = null;
            HttpWebRequest request = null;
            string url = "http://localhost/CCWService/data.svc/getcrime/";
            string strResult = string.Empty;
            //declare httpwebrequest wrt url defined above
            HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(url);
            //set method as post
            webrequest.Method = "GET";
            //set content type
            webrequest.ContentType = "application/x-www-form-urlencoded";
            //declare & read response from service
            HttpWebResponse webresponse = (HttpWebResponse)webrequest.GetResponse();
            //set utf8 encoding
            ////Encoding enc = System.Text.Encoding.GetEncoding("utf-8?);
            //read response stream from response object
            StreamReader loResponseStream = new StreamReader(webresponse.GetResponseStream());
            //read strings from stream data
            strResult = loResponseStream.ReadToEnd();
            //Close the stream object
            //Close the response object
            // assign the final result to text box
            //GridView1_SelectionChanged = strResult;

    at the top, I declare using System.Net;
    But there is still error for .GetResponse & loResponseStream.Close & webresponse.Close

    Monday, July 2, 2012 8:04 AM