DiscoveryClientProtocol DiscoverWebServices(string url)
		{
			WebServiceDiscoveryClientProtocol protocol = new WebServiceDiscoveryClientProtocol();
			NetworkCredential credential = CredentialCache.DefaultNetworkCredentials;
			bool retry = true;
			while (retry) {
				try {
					protocol.Credentials = credential;
					protocol.DiscoverAny(url);
					protocol.ResolveOneLevel();
					return protocol;
				} catch (WebException ex) {
					if (protocol.IsAuthenticationRequired) {
						using (UserCredentialsDialog dialog = new UserCredentialsDialog(url, protocol.GetAuthenticationHeader().AuthenticationType)) {
							if (dialog.ShowDialog(WorkbenchSingleton.MainWin32Window) == DialogResult.OK) {
								credential = dialog.Credential;
							} else {
								retry = false;
							}
						}
					} else {
						throw ex;
					}
				}
			}
			return null;
		}
Пример #2
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();
     }
 }
Пример #3
0
        /// <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 });
                    }
                }
            }
        }
Пример #4
0
 public AsyncDiscoveryState(WebServiceDiscoveryClientProtocol protocol, Uri uri, DiscoveryNetworkCredential credential)
 {
     this.protocol   = protocol;
     this.uri        = uri;
     this.credential = credential;
 }
 /// <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();
     }
 }
		public AsyncDiscoveryState(WebServiceDiscoveryClientProtocol protocol, Uri uri, DiscoveryNetworkCredential credential)
		{
			this.protocol = protocol;
			this.uri = uri;
			this.credential = credential;
		}