Skip to main content
Home Forums Silverlight Programming Report a Silverlight Bug Can't make WCF service calls during Application Exit?
31 replies. Latest Post by prujohn on November 1, 2009.
(0)
Eric Wil...
Member
34 points
28 Posts
07-09-2008 7:44 PM |
I've subscribed an event to the application exit event as follows: Application.Current.Exit += new EventHandler(Application_Exit);
I've then implemented that method to perform a single WCF call to my service, essentially saving the user's most recent work. However, this call is not making it to the server in either IE or FF using Silverlight 2.0 beta 2. The same call works flawlessly any time other than during exit.
IlkkaP
129 points
26 Posts
07-10-2008 4:36 AM |
As the documentation states "An Exit event handler should not include long-running, re-entrant, or cyclic code, such as resetting the Silverlight plug-in control's Source property", I'd expect that async calls are out of question.
If you need to store user's work, you might consider to use isolated storage, and when user comes back, upload it to the server. Isolated storage works in app.exit event.
Hope it helps.
Ilkka
07-10-2008 9:35 AM |
I appreciate the long-running issues, but I'm not looking for any sort of response, I just want to fire a dispatch. Is there some way to make the call "OneWay" or no-reply? Isolated storage wouldn't really apply in this case since there's a good chance that the user may use a different computer on the next visit.
Allen Ch...
Star
13873 points
1,803 Posts
07-11-2008 12:06 AM |
Hi:
This feature request has been logged. I'll update here if any new information is available.
Regards
scgm11
13 points
30 Posts
10-22-2008 10:48 AM |
any update with this issue?? we are now in RTW.
Thanks
prujohn
Contributor
3579 points
704 Posts
10-22-2008 11:12 AM |
I too am interested in this feature.
rajat.barik
14 points
11 Posts
11-13-2008 5:34 AM |
Well I am also looking for a answer for this kind of situation, Is there any way to call the database services or web services, if any user close the browser directly in silverlight application.
Thanks for your reply in advanced.
neaflo
45 points
35 Posts
11-15-2008 9:20 AM |
I subscribe to this issue too. A logoff action invoking a web service on application exit is such a common scenario ... we must have a way to do this! I believe I could invoke the web service without using the proxy and use IAsyncResult for waiting for the call completion.
cce1911
8 points
17 Posts
01-06-2009 10:39 PM |
I'm joining the club. I want to record a logout in my database when the user closes the browser.
sl_ananya
16 points
21 Posts
01-15-2009 3:34 AM |
Any update on this feature??
kobruleht
162 points
584 Posts
02-01-2009 4:43 AM |
I'm also subscribing to this.
I need to track logged in users and thus execute web service call if user closes browser window.
Is it possible to send some sync notification to server like HTTP GET request in Exit event ?
http://silverlight.net/forums/p/69833/168604.aspx#168604
SilverDK
6 points
02-02-2009 7:41 AM |
Any news on this ? This message thread is quite old and I am in this exact situation.
KurtJulius
4 points
2 Posts
02-06-2009 4:40 AM |
Hi,
i need a solution for this problem too. Writing a silverlight/wcf application for my bachelor degree, it would be nice, if someone can help me out.
02-06-2009 5:44 AM |
Just an update for this issue. Bad news is it's considered as by design because there is no mechenism to prevent a page from being unloaded. Good news is we probably can use XMLHttpRequest to workaround it.
http://www.w3schools.com/ajax/ajax_browsers.asp
02-08-2009 2:19 AM |
Allen Chen – MSFT:Just an update for this issue. Bad news is it's considered as by design because there is no mechenism to prevent a page from being unloaded. Good news is we probably can use XMLHttpRequest to workaround it. http://www.w3schools.com/ajax/ajax_browsers.asp
Could you give an example on how you can have a last contact with the WCF service on the silverlight application exit ?
02-08-2009 10:02 PM |
Instead of do that in Application_Exit we can call web service in the body's onunload event. Here's a sample:
aspx:
<%
<
}
</
web.config:
Service1.svc.cs:
using
{
IService1.cs:
[
hyaki
5 points
4 Posts
03-19-2009 3:27 PM |
Waw.. thanks for the sample... I have problem with the call.
The service i'm trying to call is required parameter. Could you kindly give me example with parameter call.
Thanks :)
TriumphO...
23 points
61 Posts
05-06-2009 8:23 AM |
Thanks for your workaround via the call through aspx. However my problem (as it seems many of those who contributed to this thread before) is that I need to save data which are stored within my silverlight control. So there are two question
- Is it possible at all to get these data from outside (which means from the aspx page) in order so send the to some place?
- And if this is possible, is it still possible in the unload event or is that too late?
As others had the same problem, I need to write the Logout information of the currently logged in user into my database that is talked to through the WCF service. So for this I need to send to my WCF service the currently logged in user as a parameter. Additionally I would like to save the latest data changes back to the backend.
NadineNDS
7 points
10 Posts
08-13-2009 9:36 AM |
I join the others. I also have to log off my users in the WCF Service with information inside the Silverlight part. Isn't there really another way?
Cheers.
Aaron Ed...
39 points
08-25-2009 5:03 PM |
The workaround is actually quite simple, and only requires some basic browser integration:
var blocking = true; function pageUnloading() { var control = document.getElementById("<%= Xaml1.ClientID%>"); // Needed if you use master pages control.content.Page.finalSave(); while (blocking) alert('Saving data to server'); } function allowClose() { blocking = false; }
HtmlPage.RegisterScriptableObject("Page", this);
[ScriptableMember()] public void finalSave() { proxy.saveDataAsync(currentObject); } void proxy_saveDataCompleted(object sender, saveDataCompletedEventArgs e) { // tells JavaScript to stop blocking HtmlPage.Window.CreateInstance("allowClose"); }
Aaron
08-27-2009 11:41 AM |
Thank you. Questions:
1. This requires that html page is processed by asp.net since contains <%= tag. How to use it in reqular html page, without asp net tag ?
2. How to modify this code so it works in OOB application also?
Andrus.
devisk
3 Posts
09-01-2009 5:49 PM |
Thank you Aaron,
I was also looking for a workaround to disconnect the client on closing the browser.
I tried your proposed solution and it does not seem to be working for me. First, I get an error while running the app at document.getElementById("<%= Xaml1.ClientID%>"); . What is supposed to be in the parameter?
09-03-2009 12:37 PM |
The use of document.getElementById("<%= Xaml1.ClientID%>") isn't required. If you're using ASP.NET MasterPages or UserControls, it simplifies things a lot, because ASP will generate different ID's for the DOM-level objects at runtime. For Example, if your SIlverlight control is located within a User Control, located within a MasterPage, the actual ID of the rendered Silverlight object might be something like MyMasterPage$MyUserControl$MySilverlightClient. And of course that's the ID that the JavaScript getElementById function would have to find.
You can always hard code the ID directly into your JavaScript, as in document.getElementById("MyMasterPage$MyUserControl$MySilverlightClient"). Nothing wrong with that. Just look at the source code from the rendered page and copy the ID from there.
09-03-2009 12:48 PM |
I was using the default test.aspx page created by Silverlight project. By default the "object" tag did not had the ID attribute so I added.
09-03-2009 1:04 PM |
Silverlight shows some exceptions javascript error handler in default page.
Can we use this method also to forward those errors to SL application which calls web method to store errors in server database for easy error tracking ?
09-03-2009 1:12 PM |
Sure, why not?
brauliod
Participant
1169 points
472 Posts
09-07-2009 8:55 AM |
Hello,
Has this been finally fixed on Silverlight 3.0?
If not.. it would be a pain in the neck implementing an autosave functionallity.
Braulio
Daze55
227 points
111 Posts
10-15-2009 4:15 AM |
Hello, I have the necessity to decrease the number of connected users when the Silverlight application is closed. I tried Aaron's solution and it worked BUT I absolutely need to get rid of the alert message, the web service must be called and the app must be close immediately whatever the result of the call, it must be 100% transparent to the user. I tried everything and nothing worked, do you know how to allow the call to the web service without any "alert" message box ?
10-15-2009 7:47 AM |
If you find a way to do it without the alert box, let us know. I tried many different things, but nothing worked consistently.
10-15-2009 10:55 AM |
Actually Aaron I set my last hope in that forum. I worked with my company Javascript most expert in order to solve the issue and we have not succeeded. The problem is that Javascript is mono-thread and that we have no way to hold the application from closing and to let it work at the same time. I really hope that something will be done for that in the next release because it's a rather serious issue IMHO. How should I determine the number of connected user now, that’s a good question...
10-31-2009 6:19 PM |
Aaron solution issues/questions:
a. It works in IE only. How to make it work in all browsers ?
b. We need to show localized exit message according to user language.How to pass custome message from silverlight application to alert box ?
c. if server or connection goes down, only way to close browser is use task manager.How to add timeout so that if there is no response from server, alert box closes after some time?
Of cource, best solution would be to remove alert box.
Andrus
11-01-2009 8:34 AM |
I recall that turbotax.com is able to do this somehow. Whenever you are in a tax return and close the browser, they pop up another browser window that says "closing connection..." or something like that. Then after a moment, that window closes as well. Not sure if they are using ActiveX though...