Timeout inside a Task from WCF

PekkachuPekkachu USMember ✭✭
edited February 2017 in Xamarin.Forms

After a couple of days messing with WCF Services, i finally managed to create a working Proxy using SLSvcutil and applying Async/Await with Tasks using others advices about wrapping IAsyncResult like this:

 public async Task<tPdtUser> GetUserAsync(string user, string pass)
        {
            return await Task.Factory.FromAsync(((IUser)client.InnerChannel).BeginsPdtUserValidateCredentials,
                                                                       ((IUser)client.InnerChannel).EndsPdtUserValidateCredentials, user, pass, null);

        }

Everything works great now, but i'm having a hard time out figuring out:

How can i validate a Timeout in the request? If no response is given (ex in 5 secs) throw a Timeout Exception?

I've read that i can use Task.WhenAny but as now, if i use this code:

var user = await Repository.GetUserAsync(Username, Password);

Response is a model object (tPdtUser) and not really a Task so im stuck with this

Any help will be greatly appreciated!

Tagged:
Sign In or Register to comment.