WCF开发工具是一个功能强大的由微软公司开发的.NET Framework 3.5的重要组成部分。它的应用可以帮助我们实现一个可靠性的开发框架。在这里我们先来为大家介绍一下WCF实现loading功能的相关操作。
WCF实现loading功能步骤1.建立WCF project
默认的方法改为
public string GetData(int value)
{
System.Threading.Thread.Sleep(5000); //模拟等待
return string.Format("You entered: {0}", value);
}
- 1.
- 2.
- 3.
- 4.
- 5.
就加一句
System.Threading.Thread.Sleep(5000); //模拟等待2.加入MCF/MCF.aspx VIEW
< %@ Page Title="" Language="C#" MasterPageFile=
"~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
< asp:Content ID="Content1" ContentPlaceHolderID=
"TitleContent" runat="server">
WCF
< /asp:Content>
< asp:Content ID="Content2" ContentPlaceHolderID="MainContent"
runat="server">
< script src="http://www.cnblogs.com/Scripts/jquery-1.3.2.js"
type="text/javascript">< /script>
< script language="javascript" type="text/javascript">
$(function() {
});
< /script>
< h2>
WCF< /h2>
< %using (Html.BeginForm())
{ %>
< div id="divResult">
< h3>
Result< /h3>
< fieldset>
< div id="divLoading">
< img src='< %=Url.Content("~/Content/images/loader.gif")%>'
alt="load" />
please waiting...< /div>
< div id="DivResultData">
< /div>
< /fieldset>
< /div>
< %} %>
< /asp:Content>3.写Action,WCFController.cs
public class WCFController : Controller
{
//
// GET: /WCF/
public ActionResult WCF()
{
return View();
}
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult WCFTest()
{
string strResult=string.Empty;
WCFTest.Service1 testClient = new WCFTest.Service1();
strResult = testClient.GetData(1);
return Json(strResult);
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
WCF实现loading功能步骤2.编写等待的loading..效果
$(function() {
$.ajax({
type: "get",
url: "WCFTest",
datatype: "Json",
data: "",
complete: function() {
$("#divLoading").css("display", "none");
},
success: function(data) {
$("#DivResultData").html(data);
}
});
});
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
WCF实现loading功能步骤3.调用WCF
public ActionResult WCFTest()
{
string strResult=string.Empty;
WCFTest.Service1 testClient = new WCFTest.Service1();
strResult = testClient.GetData(1);
return Json(strResult);
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
以上就是对WCF实现loading功能的相关介绍。
【编辑推荐】