0

How do I call a webservice in the Application_Exit event?

private void Application_Exit(object sender, EventArgs e)
{
  TestWSSoapClient.ReleaseUserCompleted += new EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(TestWSSoapClient_ReleaseUserCompleted);
  TestWSSoapClient.ReleaseUserAsync(UserToken);
}

The method below is no longer executed.

void TestWSSoapClient_ReleaseUserCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{

}

Thank you in advance.

AnthonyWJones
  • 187,081
  • 35
  • 232
  • 306
Pratik
  • 51
  • 1
  • 6
  • 1
    It's too late to call an Async service and expect a result by the time you get to Application_Exit. What are you trying to solve? Most workarounds that try to do something on Silverlight shut-down do it via JScript in the hosting page instead. – iCollect.it Ltd Nov 11 '10 at 08:49
  • Duplicate question of http://stackoverflow.com/questions/4010064/how-to-call-a-service-when-a-silverlight-oob-app-is-closing-an/4010340#4010340 – Jay Nov 11 '10 at 17:30

2 Answers2

1

You can't call any web services when exiting by design, however this article might help you with an Javascript alternative.

Chris S
  • 64,770
  • 52
  • 221
  • 239
0

Do you really need to get the response? You won't be able to get it as all threads will be closed at the end of the Application_Exit function. But if it doesn't matter, you can configure your "ReleaseUser" operation as OneWay.

As I didn't test it, it is only a supposition, but I think it should work (and if it doesn't, well, I will learn something)

Otherwise, as said before, javascript is the only way to go, but it won't work Out of Browser.

Eilistraee
  • 8,220
  • 1
  • 27
  • 30