Пример #1
0
 /// <summary>
 /// Stops any outstanding asynchronous discovery requests.
 /// </summary>
 void StopDiscovery()
 {
     lock (this) {
         if (discoveryClientProtocol != null)
         {
             try {
                 discoveryClientProtocol.Abort();
             } catch (NotImplementedException) {
             } catch (ObjectDisposedException) {
                 // Receive this error if the url pointed to a file.
                 // The discovery client will already have closed the file
                 // so the abort fails.
             }
             discoveryClientProtocol.Dispose();
         }
         discoveryClientProtocol = new WebServiceDiscoveryClientProtocol();
     }
 }
Пример #2
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 });
                    }
                }
            }
        }
 public AsyncDiscoveryState(WebServiceDiscoveryClientProtocol protocol, Uri uri, DiscoveryNetworkCredential credential)
 {
     this.protocol   = protocol;
     this.uri        = uri;
     this.credential = credential;
 }