如何使用post / put WCF RestFul服务

时间:2015-01-30 08:54:12

标签: asp.net c#-4.0 wcf-rest

我在wcf restful service中进行crud操作(使用存储过程)。我已经完成了创建服务,但是如何在我的普通ASP.net应用程序中使用该服务(没有Javascript,Jquery,AJAX) 即可。因为我是WCF休息服务的新手.Plz给我一步一步的操作。

1 个答案:

答案 0 :(得分:1)

         string sURL =  @"http://localhost:50353/urUriName/"+ txtfname.Text;
        WebRequest webGETURL;

        webGETURL = WebRequest.Create(sURL);
       webGETURL.Method = "DELETE"; 
       webGETURL.ContentType = @"Application/Json; charset=utf-8";
      HttpWebResponse wr = webGETURL.GetResponse() as HttpWebResponse;
       Encoding enc=Encoding.GetEncoding("utf-8");
    // read response stream from response object
    StreamReader loResponseStream = new StreamReader(wr.GetResponseStream(), enc);

    // read string from stream data
    string strResult = loResponseStream.ReadToEnd();

    // close the stream object
    loResponseStream.Close();
    // close the response object
    wr.Close();
    // assign the final result to text box
    Response.Write(strResult);