WP7:无法在对WCF服务的异步调用中捕获FaultException
我目前正在开发一个
Windows Phone 7应用程序,它调用我也控制的WCF Web服务.该服务提供的操作在给定用户的登录名和密码时返回当前用户的帐户信息:
[ServiceContract] public interface IWindowsPhoneService { [OperationContract] [FaultContract(typeof(AuthenticationFault))] WsAccountInfo GetAccountInfo(string iamLogin,string password); } 当然,总是存在身份验证失败的可能性,我想将这些信息传达给WP7应用程序.在这种情况下我可以简单地返回null,但我想传达验证失败的原因(即登录未知,密码错误,帐户被阻止,……). 这是我对上述操作的实现(出于测试目的,它只是抛出异常): public WsAccountInfo GetAccountInfo(string iamLogin,string password) { AuthenticationFault fault = new AuthenticationFault(); throw new FaultException<AuthenticationFault>(fault); } 现在,如果我在我的WP7应用程序中调用此操作,如下所示: Global.Proxy.GetAccountInfoCompleted += new EventHandler<RemoteService.GetAccountInfoCompletedEventArgs>(Proxy_GetAccountInfoCompleted); Global.Proxy.GetAccountInfoAsync(txbLogin.Text,txbPassword.Password); void Proxy_GetAccountInfoCompleted(object sender,RemoteService.GetAccountInfoCompletedEventArgs e) { if (e.Error != null) { MessageBox.Show(e.Error.Message); return; } } 调试器在Reference.cs中断,说FaultException’1未处理,这里: public PhoneApp.RemoteService.WsAccountInfo EndGetAccountInfo(System.IAsyncResult result) { object[] _args = new object[0]; PhoneApp.RemoteService.WsAccountInfo _result = ((PhoneApp.RemoteService.WsAccountInfo)(base.EndInvoke("GetAccountInfo",_args,result))); return _result; } 开始更新1 按F5时,异常气泡到: public PhoneApp.RemoteService.WsAccountInfo Result { get { base.RaiseExceptionIfNecessary(); // <-- here return ((PhoneApp.RemoteService.WsAccountInfo)(this.results[0])); } } 然后到: private void Application_UnhandledException(object sender,ApplicationUnhandledExceptionEventArgs e) { if (System.Diagnostics.Debugger.IsAttached) { // An unhandled exception has occurred; break into the debugger System.Diagnostics.Debugger.Break(); } } 之后,应用终止(使用或不使用调试器). END UPDATE 1 现在,我想在我的代码中捕获异常,但我从未有机会,因为我的Completed处理程序永远不会到达. 根据本网站上的类似问题,我已经尝试过以下方法: >重新添加服务参考 – >没变 开始更新2 我实际想要实现的是以下之一: >理想情况下,达到GetAccountInfoCompleted(…)并能够通过GetAccountInfoCompletedEventArgs.Error属性检索异常,或者 结束更新2 如果有任何建议可以帮助我解决这个问题,我将不胜感激. 解决方法
该框架似乎读取了您的WsAccountInfo.Result属性.
这会在客户端重新抛出异常. 但你应该是第一个阅读这个属性的人. 我不知道你的AuthenticationFault类,它是否有一个DataContractAttribute,它是一个已知类型,如示例中的 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- 如何在多台Windows机器上自动更新非Microsoft软件?
- windows – 如何在ADUC和GPMC之间链接GP对象和AD对象?
- Windows查看Java内存使用情况
- windows-installer – 如何在安装MSI时以编程方式检测成功或
- windows-server-2008 – 为什么我不能导出我导出为可导出的
- DirectX11 With Windows SDK--18 使用DirectXCollision库进
- Windows 10 + kali Linux 双系统安装教程(详细版)
- windows-8 – VariableSizedWrapGrid和WrapGrid儿童大小测量
- 在远程Windows服务器上设置Git存储库?
- .net – 在TextBox中以d / mm格式输入日期