Call webservice when Silverlight comes out

How can I call the webservice when Silverlight comes out? I need to send an update on the server when silverlight comes out.

+4
source share
6 answers

Add an event handler for the Application.Exit event. Call WebService in this handler. XAML / Code looks something like this:

<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="SilverlightApplication.App" Exit="App_Exit"> </Application> 

and

 public partial class App : Application { private void App_Exit(object sender, EventArgs e) { // Code to call WebService goes here. } } 
+3
source

You cannot make a web request when the application terminates in Silverlight.

+2
source

I had an application that was supposed to save information before closing. I used javascript on the page where the silverlight control is placed.

Javascript and usage

 <script type="text/javascript"> var blocking = true; function pageUnloading() { var control = document.getElementById("Xaml1"); control.content.Page.FinalSave(); while (blocking) alert('Saving User Information'); } function allowClose() { blocking = false; } </script> <body onbeforeunload="pageUnloading();"> </body> 

and App.xaml.cs

 public partial class App : Application { [ScriptableMember()] public void FinalSave() { srTL.TrueLinkClient proxy = new CSRM3.srTL.TrueLinkClient(); proxy.DeleteAllUserActionsCompleted += (sender, e) => { HtmlPage.Window.CreateInstance("allowClose"); }; proxy.DeleteAllUserActionsAsync(ApplicationUser.UserName); } } 
+2
source

See comments on Justin Nissner: you cannot return the return value. This may be good for you if the service you are calling is not critical (because, say, it just captures usage statistics). If you need to have a return value anyway, and you expect that the SL application will be used several times, you can write the memory to IsolStorage (this is a synchronous operation) and send it to the server the next time the application starts.

0
source

Yes, just call the web service and don't wait for a return value .. because it never arrives

Do this:

  private async void Application_Exit(object sender, EventArgs e) { // Tell DBSERVER_V14 pipe we have gone away await connect_disconnect_async(MainPage.username, MainPage.website, false); } 

But do not do this:

  private async void Application_Exit(object sender, EventArgs e) { // Tell DBSERVER_V14 pipe we have gone away var status = await SmartNibby_V13.connect_disconnect_async(MainPage.username, MainPage.website, false); if (status) { Console.WriteLine(status); } } 

because you will never have the status value you need to test with.

0
source

Source: https://habr.com/ru/post/1315406/


All Articles