/// <summary>Opens the connection.</summary> /// <returns>The result.</returns> private async Task <bool> OpenAsync() { try { this._client = new SubscriptionServiceClient(new InstanceContext(this)); // state change information (non-essential) _client.InnerChannel.Opening += async(s, e) => await _guiCallback.ConnectionStateChangedAsync("event", "Connection opening..."); _client.InnerChannel.Opened += async(s, e) => await _guiCallback.ConnectionStateChangedAsync("event", "Connection opened."); _client.InnerChannel.Closing += async(s, e) => await _guiCallback.ConnectionStateChangedAsync("event", "Connection closing..."); // maintaining the connection! // Note: These events come for netTcpBinding, but NOT for wsDualHttpBinding! _client.InnerChannel.Closed += InnerChannel_ClosedAsync; _client.InnerChannel.Faulted += InnerChannel_FaultedAsync; _client.Open(); // failure to open will also raise a faulted event! return(true); } catch (Exception ex) { await _guiCallback.ServiceCallExceptionAsync("Open", ex); return(false); } }
private async Task <TResult> CallAsync <TResult>(string operation, Func <InformationServiceReference.InformationServiceClient, Task <TResult> > call) { // basic error handling try { var client = new InformationServiceReference.InformationServiceClient(); return(await call(client)); } catch (Exception ex) { await _guiCallback.ServiceCallExceptionAsync(operation, ex); return(default(TResult)); } }