Windows phone 7,silverlight

编程入门 行业动态 更新时间:2024-10-26 02:27:54
本文介绍了Windows phone 7,silverlight - 如何在调用异步 Web 服务时捕获 EndpointNotFoundException?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在从 Silverlight Windows phone 7 应用程序中调用 Web 服务,如果该 Web 服务可用,该应用程序就可以正常工作.如果 Web 服务不可用,则会捕获未处理的异常,但我自己似乎无法捕获它.我的尝试如下:

I'm calling a web service from within a Silverlight Windows phone 7 application which works fine if the web service is available. If the web service is unavailable then an unhandled exception is caught but I don't seem able to catch it myself. My attempt is as follows:

            //Get list of providers from Webservice
        RSAServiceClient proxy = new RSAServiceClient();
        proxy.GetSuppliersCompleted += new System.EventHandler<GetSuppliersCompletedEventArgs>(ProxyGetSuppliersCompleted);
        try
        {
            proxy.GetSuppliersAsync();
        }
        catch (EndpointNotFoundException)
        {
            //TODO: Handle webserice not being available
        }
        catch (Exception)
        {
            throw;
        }

但这并没有捕获异常,显然 GetSuppliersCompleted 永远不会被调用,所以我无法在那里捕获它.

But this doesn't catch the exception and obviously GetSuppliersCompleted never get's called so I can't catch it there.

然后我认为我可以通过检查连接状态 (proxy.State) 来检测它,但是尽管 Web 服务没有运行,但返回 CommunicationState.Opened.

I then thought I may be able to detect it by checking the connection state (proxy.State) but this despite the web service not running returns CommunicationState.Opened.

知道我可以在哪里处理吗?

Any idea's where I can handle this?

如果我错过了一些东西,但我已经搜索过但没有找到解决方案,我们深表歉意.

Apologies if I've missed something but I have searched and not found a solution.

推荐答案

您应该将您的捕获放在您的 ProxyGetSuppliersCompleted 方法中.

You should place your catch in your ProxyGetSuppliersCompleted method.

尝试访问结果将抛出您期望的错误.

An attempt to access the result will throw the error you are expecting.

或者在 ProxyGetSuppliersCompleted 中,您可以测试将包含异常的 EventArgs 的 Error 属性.

Alternatively in the ProxyGetSuppliersCompleted you can test the Error property of the EventArgs which will contain the exception.

这篇关于Windows phone 7,silverlight - 如何在调用异步 Web 服务时捕获 EndpointNotFoundException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-26 06:24:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1130473.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Windows   phone   silverlight

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!