示例#1
0
        /// <summary>
        /// Called after an asynchronous web services search has
        /// completed.
        /// </summary>
        private void DiscoveryCompleted(IAsyncResult result)
        {
            AsyncDiscoveryState state = (AsyncDiscoveryState)result.AsyncState;
            WebServiceDiscoveryClientProtocol protocol = state.Protocol;

            // Check that we are still waiting for this particular callback.
            bool wanted = false;

            lock (this)
            {
                wanted = Object.ReferenceEquals(_discoveryClientProtocol, protocol);
            }

            if (wanted)
            {
                DiscoveredWebServicesHandler handler = new DiscoveredWebServicesHandler(DiscoveredWebServices);
                try
                {
                    DiscoverAnyAsync  asyncDelegate = (DiscoverAnyAsync)((AsyncResult)result).AsyncDelegate;
                    DiscoveryDocument doc           = asyncDelegate.EndInvoke(result);
                    if (!state.Credential.IsDefaultAuthenticationType)
                    {
                        AddCredential(state.Uri, state.Credential);
                    }
                    Invoke(handler, new object[] { protocol });
                }
                catch
                {
                    if (protocol.IsAuthenticationRequired)
                    {
                        HttpAuthenticationHeader authHeader  = protocol.GetAuthenticationHeader();
                        AuthenticationHandler    authHandler = new AuthenticationHandler(AuthenticateUser);
                        Invoke(authHandler, new object[] { state.Uri, authHeader.AuthenticationType });
                    }
                    else
                    {
                        //LoggingService.Error("DiscoveryCompleted", ex);
                        Invoke(handler, new object[] { null });
                    }
                }
            }
        }
        /// <summary>
        /// Called after an asynchronous web services search has
        /// completed.
        /// </summary>
        void DiscoveryCompleted(IAsyncResult result)
        {
            AsyncDiscoveryState state = (AsyncDiscoveryState)result.AsyncState;
            WebServiceDiscoveryClientProtocol protocol = state.Protocol;

            // Check that we are still waiting for this particular callback.
            bool wanted = false;
            lock (this) {
                wanted = Object.ReferenceEquals(discoveryClientProtocol, protocol);
            }

            if (wanted) {
                DiscoveredWebServicesHandler handler = new DiscoveredWebServicesHandler(DiscoveredWebServices);
                try {
                    DiscoverAnyAsync asyncDelegate = (DiscoverAnyAsync)((AsyncResult)result).AsyncDelegate;
                    DiscoveryDocument doc = asyncDelegate.EndInvoke(result);
                    if (!state.Credential.IsDefaultAuthenticationType) {
                        AddCredential(state.Uri, state.Credential);
                    }
                    Invoke(handler, new object[] {protocol});
                } catch (Exception ex) {
                    if (protocol.IsAuthenticationRequired) {
                        HttpAuthenticationHeader authHeader = protocol.GetAuthenticationHeader();
                        AuthenticationHandler authHandler = new AuthenticationHandler(AuthenticateUser);
                        Invoke(authHandler, new object[] {state.Uri, authHeader.AuthenticationType});
                    } else {
                        LoggingService.Error("DiscoveryCompleted", ex);
                        Invoke(handler, new object[] {null});
                    }
                }
            }
        }