简体   繁体   English

Windows phone 7,silverlight - 如何在调用异步Web服务时捕获EndpointNotFoundException?

[英]Windows phone 7, silverlight - How to catch EndpointNotFoundException when calling async web service?

I'm calling a web service from within a Silverlight Windows phone 7 application which works fine if the web service is available. 我正在从Silverlight Windows phone 7应用程序中调用Web服务,如果Web服务可用,它可以正常工作。 If the web service is unavailable then an unhandled exception is caught but I don't seem able to catch it myself. 如果Web服务不可用,则会捕获未处理的异常,但我似乎无法自己捕获它。 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;
        }

But this doesn't catch the exception and obviously GetSuppliersCompleted never get's called so I can't catch it there. 但是这并没有捕获异常,显然GetSuppliersCompleted永远不会被调用,所以我无法在那里捕获它。

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. 然后我想我可以通过检查连接状态(proxy.State)来检测它,但是尽管Web服务没有运行,但是返回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. 抱歉,如果我错过了一些东西,但我已经搜索过但没有找到解决方案。

You should place your catch in your ProxyGetSuppliersCompleted method. 您应该将catch放在ProxyGetSuppliersCompleted方法中。

An attempt to access the result will throw the error you are expecting. 尝试访问结果将引发您期望的错误。

Alternatively in the ProxyGetSuppliersCompleted you can test the Error property of the EventArgs which will contain the exception. 或者在ProxyGetSuppliersCompleted您可以测试将包含异常的EventArgs的Error属性。

I recommend to check if you you have access to Internet before you fire any peace of code. 我建议您在解决任何代码安静之前检查您是否可以访问Internet。 Just check if there is net connection and notifi the user if not. 只检查是否有网络连接,如果没有则通知用户。

I have exactly the same problem. 我有完全一样的问题。 The behaviour is different from Desktop-Silverlight where the exception is handled, to WindowsPhone-Silverlight where connection exceptions are not handled at all. 行为与处理异常的Desktop-Silverlight不同,WindowsPhone-Silverlight根本不处理连接异常。

I created a topic here : http://forums.create.msdn.com/forums/t/69485.aspx 我在这里创建了一个主题: http//forums.create.msdn.com/forums/t/69485.aspx

Nobody has any real answer. 没有人有任何真正的答案。 Ah, yes, there is a trick : you can manually modify the reference.cs in order to manually catch the exception.... But if you have lot of functions, it becomes a nightmare. 啊,是的,有一个技巧:你可以手动修改reference.cs以手动捕获异常....但是如果你有很多功能,它就变成了一场噩梦。

Maybe Microsoft developers didn't test all the connection usecases, and they forget to implement this one (which is a big one). 也许Microsoft开发人员没有测试所有连接用例,他们忘记实现这个(这是一个很大的)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 调用服务时EndpointNotFoundException - EndpointNotFoundException when calling a service 空肥皂:从Windows Phone 8调用Web服务时出现body - Empty soap:body when calling a web service from windows phone 8 在Windows Phone Async Service中捕获服务器端异常 - Catch a server side exception in Windows Phone Async Service 在Windows Phone Silverlight应用程序8 / 8.1中同步等待Web服务时,主线程冻结 - Main thread freezes when waiting for Web service synchronously in Windows Phone Silverlight Application 8/8.1 WCF Web服务引发EndPointNotFoundException - WCF Web service is throwing EndPointNotFoundException 在Windows Phone 8应用中调用REST Web服务时,值未在预期范围内 - Value does not fall within the expected range when calling REST web service in windows phone 8 app 调用Web服务功能从Windows Phone返回字符串[] - Calling Web Service Function returns a string[] from Windows Phone 调用Web服务时停止在Windows Phone文本框中键入内容 - Typing in a windows phone textbox stops while calling a web service 如何在Windows Phone中执行Web服务呼叫 - How to perform a web service call in Windows Phone 如何在Windows Phone Silverlight项目中创建http Web请求? - How to Create http Web Request in Windows Phone Silverlight Project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM