ASP.NET VS2010 ajax with WCF Service failure to poll. Plz help a fustrated man C#
Any help on this will save me from tearing out my hair anymore so here is the background:
I have a WCF service on the endpoint server this accepts files and reports back a percentage to the client, the client asp.net webpage is basically formatted with a label inside of an update panel, to test the update panel worked and i had the theory down i made the page update every 1000ms (timer) with date time, this worked.
I then plugged everything together stuck in some breakpoints and watched the label get updated with the percentage in the code, but the update panel no longer refreshed any ideas will save me from the countless hours I have ahead of me and make me feel happier about the ones wasted, so without further adue:
ASPX page
Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnableCdn="True" />
<asp:Timer runat="server" id="UpdateTimer" interval="1000"
ontick="UpdateTimer_Tick" />
<asp:UpdatePanel runat="server" id="TimedPanel" updatemode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger controlid="UpdateTimer"
eventname="Tick" />
</Triggers>
<ContentTemplate>
<asp:Label runat="server" id="lbldatetime" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:ListBox ID="LogListBox" runat="server" />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</form>
</body>
</html>
and .cs codebehind
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
private void LogText(string text)
{
LogListBox.Items.Add(text);
LogListBox.SelectedIndex = LogListBox.Items.Count - 1;
}
protected void Button1_Click(object sender, EventArgs e)
{
//set upload status
//hard code path for test
string sPath = @"C:\Users\joshuah\Downloads\update-cm-9.0.0-RC0-Touchpad-alpha2-fullofbugs.zip"; //bigest file i had on my laptop for testing.
try
{
// get some info about the input file
System.IO.FileInfo fileInfo = new System.IO.FileInfo(sPath);
// show start message
LogText("Starting uploading " + fileInfo.Name);
LogText("Size : " + fileInfo.Length);
// open input stream
using (System.IO.FileStream stream = new System.IO.FileStream(sPath, System.IO.FileMode.Open, System.IO.FileAccess.Read))
{
using (StreamWithProgress uploadStreamWithProgress = new StreamWithProgress(stream))
{
uploadStreamWithProgress.ProgressChanged += uploadStreamWithProgress_ProgressChanged;
uploadStreamWithProgress.ProgressChanged += UpdateTimer_Tick;
// start service client
ServiceReference1.FileTransferServiceClient client = new ServiceReference1.FileTransferServiceClient();
// upload file
client.UploadFile(fileInfo.Name, fileInfo.Length, uploadStreamWithProgress);
LogText("Done!");
// close service client
client.Close();
}
}
}
catch (Exception ex)
{
LogText("Exception : " + ex.Message);
if (ex.InnerException != null) LogText("Inner Exception : " + ex.InnerException.Message);
}
finally
{
//end wait
}
}
void uploadStreamWithProgress_ProgressChanged(object sender, StreamWithProgress.ProgressChangedEventArgs e)
{
if (e.Length != 0)
{
lbldatetime.Text = (e.BytesRead * 100 / e.Length).ToString(); // this increments fine when breakpointing
}
}
protected void UpdateTimer_Tick(object sender, EventArgs e)
{
if (lbldatetime.Text.Length > 0) //breakpoint here i can see the
{
TimedPanel.Update(); // added this to proove the timer was ticking
}
}
}
}
Sorry if i missed anything, and thanks for looking Y'all :)