开发者

asp.net Ajax Timer to poll a WCF service

开发者 https://www.devze.com 2022-12-13 07:51 出处:网络
I am using a asp:Timer control to poll a service every 10 seconds. I know the timer is working as if I comment out the service call the time will update the panel perfectly.

I am using a asp:Timer control to poll a service every 10 seconds.

I know the timer is working as if I comment out the service call the time will update the panel perfectly.

However when the service call is enabled the timer will update the panel a few times correctly but then it will start to hang.

I believe it's due to a bottle neck at the service side but the service just retu开发者_如何学Crns a list of projects.

Here is the code in each level:

ASP.Net

<asp:UpdatePanel ID="pnlProjectList" runat="server">
<ContentTemplate>
<asp:Timer id="updateTimer" Interval="10000" runat="server" 
        ontick="updateTimer_Tick">
</asp:Timer>

C# page code behind

public partial class Controls_ProjectList : System.Web.UI.UserControl, IProjectListView
{
ProjectListPresenter presenter;

protected void Page_Load(object sender, EventArgs e)
{
    presenter = new ProjectListPresenter(this);
    if (!IsPostBack)
    {
        presenter.GetProjects();
        lbUpdateTime.Text = "Updated at " + DateTime.Now.ToLongTimeString();
    }
}

public ProjectTable ProjectList
{
    set { 
        dlProjectList.DataSource = value.Projects;
        dlProjectList.DataBind();
    }
}
protected void updateTimer_Tick(object sender, EventArgs e)
{
    try
    {
        presenter.GetProjects();
        lbUpdateTime.Text = "Updated at " + DateTime.Now.ToLongTimeString();
    }
    catch (TimeoutException ex)
    {

    }
}

}

Can anyone advise me on A)what I'm doing wrong or B)the best practices for doing what I am trying to do.

Thanks.


Could be down to any number of things. Try to use Trace Viewer to analyse WCF communications in more detail and find out when and where the errors are encountered.

Within your .config files, you can add blocks. To enable tracing, simply add dignostics blocks and trace files will be generated in the specified location when the app is run. This should enable you to dig a little deeper with the problem.

Trace viewer can be found:

("C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\SvcTraceViewer.exe")

Info on trace viewer usage: http://msdn.microsoft.com/en-us/library/aa751795.aspx


I solved the issue.

Basically, each time the Tick event is being called the page load event was being fired meaning that it was creating a new presenter. Each new presenter was creating a new connection to the service and none of the connections were being closed so it overloaded the service.

Now I have a function to close the connection which is called after each method call to the service.

0

精彩评论

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