Note that there are some explanatory texts on larger screens.

plurals
  1. POWP7: Unable to catch FaultException in asynchronous calls to WCF service
    primarykey
    data
    text
    <p>I am currently developing a Windows Phone 7 App that calls a WCF web service which I also control. The service offers an operation that returns the current user's account information when given a user's login name and password:</p> <pre><code>[ServiceContract] public interface IWindowsPhoneService { [OperationContract] [FaultContract(typeof(AuthenticationFault))] WsAccountInfo GetAccountInfo(string iamLogin, string password); } </code></pre> <p>Of course, there is always the possibility of an authentication failure and I want to convey that information to the WP7 app. I could simply return null in that case, but I would like to convey the reason why the authentication failed (i.e. login unknown, wrong password, account blocked, ...).</p> <p>This is my implementation of the above operation (for testing purposes, all it does is throwing an exception):</p> <pre><code>public WsAccountInfo GetAccountInfo(string iamLogin, string password) { AuthenticationFault fault = new AuthenticationFault(); throw new FaultException&lt;AuthenticationFault&gt;(fault); } </code></pre> <p>Now, if I call this operation in my WP7 app, like this:</p> <pre><code>Global.Proxy.GetAccountInfoCompleted += new EventHandler&lt;RemoteService.GetAccountInfoCompletedEventArgs&gt;(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; } } </code></pre> <p>The debugger breaks in Reference.cs, saying that FaultException'1 was unhandled, here: </p> <pre><code>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; } </code></pre> <p><strong>BEGIN UPDATE 1</strong></p> <p>When pressing F5, the exception bubbles to:</p> <pre><code>public PhoneApp.RemoteService.WsAccountInfo Result { get { base.RaiseExceptionIfNecessary(); // &lt;-- here return ((PhoneApp.RemoteService.WsAccountInfo)(this.results[0])); } } </code></pre> <p>and then to:</p> <pre><code>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(); } } </code></pre> <p>After that, the app terminates (with or without the debugger).</p> <p><strong>END UPDATE 1</strong></p> <p>Now, I would love to catch the exception in my code, but I am never given the chance, since my Completed handler is never reached. </p> <p>Based on similar questions on this site, I have already tried the following:</p> <ul> <li>Re-add the service reference --> no change</li> <li>Re-create a really simple WCF service from scratch --> same problem</li> <li>Start the app without the debugger to keep the app from breaking into the debugger --> well, it doesn't break, but the exception is not caught either, the app simply exits</li> <li>Tell VS 2010 not to break on FaultExceptions (Debug > Options) --> does not have any effect</li> <li>wrap every line in my app in try { ... } catch (FaultException) {} or even catch (Exception) --> never called.</li> </ul> <p><strong>BEGIN UPDATE 2</strong></p> <p>What I actually would like to achieve is one of the following:</p> <ul> <li><p>ideally, reach GetAccountInfoCompleted(...) and be able to retrieve the exception via the GetAccountInfoCompletedEventArgs.Error property, or</p></li> <li><p>be able to catch the exception via a try/catch clause</p></li> </ul> <p><strong>END UPDATE 2</strong></p> <p>I would be grateful for any advice that would help me resolve this issue.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload