Silverlight退出时如何调用webservice? silverlight退出时,我需要在服务器上发送更新。Silverlight退出时调用webservice
4
A
回答
1
3
为Application.Exit事件添加事件处理程序。在该处理程序中调用WebService。在XAML /代码看起来是这样的:
<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>
而且
public partial class App : Application
{
private void App_Exit(object sender, EventArgs e)
{
// Code to call WebService goes here.
}
}
0
查看贾斯汀Niessner的答案的评论:你不能取回返回值。如果您所调用的服务不是关键性的(因为我们假设它只是捕获一些使用情况统计信息),那对您来说可能是正确的。如果您需要任何情况下都有返回值,并且您希望多次使用SL应用程序,则可以将记事本写入IsolatedStorage(即同步操作),并在应用程序启动时将其发布到服务器下次。
2
您无法在Silverlight中关闭应用程序的Web请求。
2
我有一个应用程序需要在关闭前保存信息。我在托管Silverlight控件的页面中使用了javascript。
Javascript和使用
<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>
和 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);
}
}
+0
javascript while while block在不同的浏览器上引发警报,运行的脚本失去控制......除此之外,这似乎工作 – Rumplin 2011-03-23 07:43:11
0
是的,只是做的Web服务调用,不等待返回值..因为它永远不会到达
所以做到这一点:
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);
}
但不这样做:
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);
}
}
,因为你永远不会有一个“状态”值与测试。
相关问题
- 1. 调用webservice时出错
- 2. 使用jquery调用webservice时出错
- 3. 从JQuery调用webservice时出错
- 4. 从android类调用webservice时出错
- 5. 当应用程序退出时使用对象更新webservice
- 6. Silverlight退出沙箱吗?
- 7. lein deps在从Dockerfile调用时退出
- 8. CommunicationException从Silverlight中调用WCF时出现
- 9. Silverlight调用服务时出错
- 10. 取消Silverlight OOB应用程序退出?
- 11. 如何从Silverlight 4.0应用程序调用WebService时更改超时限制?
- 12. 使用webservice时出错
- 13. 在退出时保留Silverlight应用程序中的值
- 14. 退出浏览器调用
- 15. Silverlight - 尝试POST到webservice时出现异常
- 16. webservice调用另一个webservice
- 17. 为什么visual studio在应用程序退出时退出调试器?
- 18. Ajax调用webservice
- 19. Ajax调用webservice
- 20. 调用asp.net webservice
- 21. 调用restfull webservice抛出错误的URI
- 22. 使用$(func)调用有问题的函数时,Bash脚本不会退出第一个“退出”调用
- 23. 使用sendSynchronousRequest调用webservice时更新UI
- 24. 防止在退出到弹出窗口时调用mouseExited
- 25. Silverlight 4退出浏览器并升级
- 26. Silverlight退出浏览器检查
- 27. Silverlight退出浏览器问题
- 28. Silverlight退出SharePoint webpart中的浏览器
- 29. Silverlight 3退出浏览器更新
- 30. Silverlight退出浏览器主机
+1实际上是一个很好的问题 – 2011-03-04 14:12:30