开发者

using wcf instead of web service !

I'm using ajax in my website to call some information from a UserControl called NewsFeed.ascx which is found in the folder 'controls', my way is to make a web service page (in a folder called WebMethods) which contain a function in my case called GetRSSReader which returns a string format:

    [WebMethod]开发者_运维知识库
public string GetRSSReader()
{
    Page page = new Page();
    UserControl ctl =
      (UserControl)page.LoadControl("~/Controls/NewsFeed.ascx");

    page.Controls.Add(ctl);

    StringWriter writer = new StringWriter();
    HttpContext.Current.Server.Execute(page, writer, false);

    return writer.ToString();
}

then I call this page using Jquery (which I found it too heavy) to get the returned data as a JSON like this :

<div id="Content"></div>
<script type="text/javascript" defer="defer" src="../JAVA/Default.js"></script>

>

$(document).ready(Update);

function Requests()
{
  $.ajax({
    type: "POST",
    url: "../WebMethods/Feed.asmx/GetRSSReader",
    data: "{}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function(msg) {
      $('#Content').html(msg.d);
    }
  });
}

the Jquery.js and this page (default.js) founded in the folder Java

my question : can I not to use webService and instead using WCF !!! and how !?


What you refer to as "web services" is the old "ASMX Web Service" feature of .NET (sometimes known as ASP.NET Web Services).

WCF is the replacement for ASMX web services.

See https://stackoverflow.com/tags/wcf/info for some getting-started information.


If you're just returning JSON then I highly recommend you simply use an HttpHandler instead of some combination of WCF, SOAP, UserControls, and whatever else you're throwing in there. Here's a quick tutorial on the subject. You'd save yourself the overhead of page life-cycle stuff that you don't need. And returning the JSON is as simple as serializing your return values with the JavaScriptSerializer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜