Monday, March 26, 2012

PROBLEM - Timer Control calling Web Service?

Hi,

I have an issue, where I need to utiliize the AJAX Timer Control to continously poll an AJAX Web Service. Now I have successfully been calling the Web Service directly from Javascript, without any issue, however I need to perform some server-side actions.

Hence i need to use the Timer control to perform a onTick event call, which uses the same AJAX Web Service on the server side as follows:

iWebService ws = new iWebService();

string response = ws.iFunction("some data");

The problem here is i recieve the following error on every interval call from the Timer;

Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occured while processing the request on the server. The status code returned from the server was: 500

If anyone can help here, then that would be great, otherwise a temporary solution for my problem is to get the Timer to call a client side function instead of the server side one, and then for me to make a traditional Javascript request to the Web Service. If anyone knows how to do this, I would be very greatful.

Thank you!

We'd need to see some code to figure out what's going on, but rather than using the server Timer control, you're probably better off downloading the Futures January CTP and using the Sys.Preview.Timer control in there.

Hi, Steve

<formid="mainform"runat="server">

<asp:ScriptManagerID="ScriptManager1"runat="server"><Services><asp:ServiceReferencePath="iWebService.asmx"/></Services></asp:ScriptManager><asp:Timerid="timToolBar"runat="server"OnTick="Refresher"Interval="5000"></asp:Timer><asp:UpdatePanelID="upToolBar"runat="server"UpdateMode="Conditional"><Triggers><asp:AsyncPostBackTriggerControlID="timToolBar"/></Triggers><ContentTemplate><uc2:ctrlToolBarID="ToolBar"runat="server"/></ContentTemplate></asp:UpdatePanel>
//CODE BEHIND FILE 

protected void Refresher(object sender, EventArgs e)

{

iMediaService ws =newiMediaService();

string response = ws.GetEvent(sessionid.Value, 2000);

//Some code here to update the Toolbar

}

It's pretty simple to be honest, the call to the WS basically returns some info I use to update the ToolBar. I need to call the WS continuosly, but information is only returned if the iWebService.RegisterClient is called first, before this, the call to GetEvent returns an empty string, which is correct. But after the RegisterClient has been called, i should get some data back from every call to the ws.GetEvent function.

Simple Call Logic

1. Register Client

2. Repeat call to GetEvent & Update ToolBar

The first call to GetEvent after the RegisterClient works fine and i recieve the correct data, but after that, when the Timer fires every interval, i get that error message. The ToolBar is a Web User Control, now simply I could just output the response string from GetEvent to a TextBox for testing, but like i said, the first call is fine, after that it just throws that error.

Also as i was debugging this, the debugger was not breaking on my breakpoint on the first line of the Refresher function, i think theres a problem after i write some info to the ToolBar.


The 500 suggests that something's breaking on the server. I would recommend grabbingNikhil's Web Development Helper and taking a look at the request and 500 response. It's quite likely the contents of the response will show you exactly what the problem is.

(As it is, I can't really guess what's going wrong.)

No comments:

Post a Comment