protected void Authenticate() { // virtual method call to get the client credentials ICredentials clientCredentials; if (!this.TryCreateCredentials(this.serviceUri, out clientCredentials)) { return; } ClientSettings settings = new ClientSettings { Credentials = clientCredentials, RequestTimeout = Settings.Default.ClientRequestTimeout }; Task <ServiceContext> connectTask = ServiceContext.ConnectAsync(this.serviceUri, settings); connectTask.OnSuccess( delegate(ServiceContext serviceContext) { this.onConnected.Invoke(serviceContext); this.IsNotConnecting = true; }); connectTask.OnFaulted( delegate(Exception error) { AggregateException aggregateException = error as AggregateException; if (aggregateException != null) { error = aggregateException.GetBaseException(); } this.ErrorMessage = error.Message; this.IsNotConnecting = true; }); connectTask.OnCanceled( delegate() { this.IsNotConnecting = true; }); }