Bagikan melalui


DiscoveryClientProtocol.Discover(String) Metode

Definisi

Menemukan URL yang disediakan untuk menentukan apakah itu adalah dokumen penemuan.

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

Parameter

url
String

URL tempat penemuan layanan Web XML dimulai.

Mengembalikan

Yang DiscoveryDocument berisi hasil penemuan layanan Web XML di URL yang disediakan.

Pengecualian

Mengakses URL yang disediakan mengembalikan kode status HTTP selain OK.

Parameter url adalah URL yang valid, tetapi tidak menunjuk ke dokumen penemuan yang valid.

Contoh

Contoh kode berikut adalah Formulir Web yang mengisi DataGrid dengan detail tentang dokumen dalam Documents properti bersama dengan referensi yang ditemukan di setiap dokumen selama penemuan layanan Web XML. Metode PopulateGrid mengisi DataGrid dengan hasil dari Discover pemanggilan diikuti dengan panggilan ke 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

Keterangan

Metode Discover ini mengharapkan bahwa URL yang disediakan adalah dokumen penemuan. Jika URL mengacu pada deskripsi layanan atau skema XML, pengecualian akan dilemparkan. Untuk menemukan skema XML atau deskripsi layanan, panggil DiscoverAny metode .

Jika URL yang disediakan menunjuk ke dokumen penemuan yang valid, dokumen penemuan di URL yang disediakan ditambahkan ke Documents koleksi dan References . Selain itu, referensi dalam dokumen penemuan ditambahkan ke References koleksi, tetapi tidak diverifikasi untuk menunjuk ke dokumen penemuan yang valid. Untuk memverifikasi referensi, arahkan ke dokumen penemuan yang ResolveAll valid untuk memanggil metode atau ResolveOneLevel .

Berlaku untuk