DiscoveryClientProtocol.Discover(String) Метод

Определение

Обнаруживает указанный URL-адрес и определяет, является ли он документом обнаружения.

public:
 System::Web::Services::Discovery::DiscoveryDocument ^ Discover(System::String ^ url);
public System.Web.Services.Discovery.DiscoveryDocument Discover (string url);
member this.Discover : string -> System.Web.Services.Discovery.DiscoveryDocument
Public Function Discover (url As String) As DiscoveryDocument

Параметры

url
String

URL-адрес, с которого начинается обнаружение веб-служб XML.

Возвращаемое значение

Класс DiscoveryDocument, содержащий результаты обнаружения веб-служб XML по указанному URL-адресу.

Исключения

При доступе к указанному URL-адресу возвращен код статуса HTTP, отличный от OK.

Параметр url является допустимым URL-адресом, но не указывает на допустимый документ обнаружения.

Примеры

В следующем примере кода используется веб-форма, которая заполняет DataGrid сведениями о документах в свойстве Documents вместе со ссылками, найденными в каждом документе при обнаружении веб-служб XML. Метод PopulateGrid заполняет DataGrid результаты вызова Discover , за которым следует вызов ResolveAll.

 protected void Discover_Click(object Source, EventArgs e)
 {
  // Specify the URL to discover.
  string sourceUrl = DiscoURL.Text;
  // Specify the URL to save discovery results to or read from.
  string outputDirectory = DiscoDir.Text;

      DiscoveryClientProtocol client = new DiscoveryClientProtocol();
  // Use default credentials to access the URL being discovered.
      client.Credentials = CredentialCache.DefaultCredentials;

      try 
      {
        DiscoveryDocument doc;
        
        // Only discover discovery documents, which might contain references to other types of discoverable documents.  
    doc = client.Discover(sourceUrl);
   
        // Resolve all possible references from the supplied URL.
        client.ResolveAll();
      }
      catch ( Exception e2) 
      {
        DiscoveryResultsGrid.Columns.Clear();
        Status.Text = e2.Message;
      }
  // If documents were discovered, display the results in a data grid.
      if (client.Documents.Count > 0)
      PopulateGrid(client);

  // Save the discovery results to disk.
      DiscoveryClientResultCollection results = client.WriteAll(outputDirectory, "results.discomap");
      Status.Text = "The following file holds the links to each of the discovery results: <b>" + 
                                  Path.Combine(outputDirectory,"results.discomap") + "</b>";
}
Public Sub Discover_Click(Source As Object, e as EventArgs )
   ' Specify the URL to discover.
   Dim sourceUrl as String = DiscoURL.Text
   ' Specify the URL to save discovery results to or read from.
   Dim outputDirectory As String = DiscoDir.Text

   Dim client as DiscoveryClientProtocol = new DiscoveryClientProtocol()
   ' Use default credentials to access the URL being discovered.
   client.Credentials = CredentialCache.DefaultCredentials
   Try 
     Dim doc As DiscoveryDocument
     ' Only discover discovery documents, which might contain references to other types of discoverable documents. 
     doc = client.Discover(sourceUrl)

 ' Resolve all possible references from the supplied URL.
     client.ResolveAll()
           
    Catch e2 As Exception
       DiscoveryResultsGrid.Columns.Clear()
       Status.Text = e2.Message
    End Try

    ' If documents were discovered, display the results in a data grid.
    If (client.Documents.Count > 0) Then
         'populate our Grid with the discovery results
     PopulateGrid(client)
    End If

    ' Save the discovery results to disk.	    
    Dim results As DiscoveryClientResultCollection 
    results = client.WriteAll(outputDirectory, "results.discomap")
    Status.Text = "The following file holds the links to each of the discovery results: <b>" + _ 
                                  Path.Combine(outputDirectory,"results.discomap") + "</b>"
   End Sub

Комментарии

Метод Discover ожидает, что указанный URL-адрес является документом обнаружения. Если URL-адрес ссылается на описание службы или схему XML, возникает исключение. Чтобы обнаружить xml-схему или описание службы, вызовите DiscoverAny метод .

Если указанный URL-адрес указывает на допустимый документ обнаружения, документ обнаружения по указанному URL-адресу добавляется в коллекцию Documents и References . Кроме того, ссылки в документе обнаружения добавляются в коллекцию References , но не проверяются, чтобы они указывали на допустимые документы обнаружения. Чтобы проверить ссылки, наведите указатель на допустимые документы обнаружения для вызова ResolveAll методов или ResolveOneLevel .

Применяется к