DiscoveryClientProtocol.DiscoverAny(String) 方法

定義

探索提供的 URL 以判斷它是否為探索文件、服務描述或 XML 結構描述定義 (XSD) 結構描述。

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

參數

url
String

URL,XML Web Service 探索在此處開始。

傳回

DiscoveryDocument,包含在所提供的 URL 處的 XML Web Service 探索結果。 如果 url 參數參考服務描述或 XSD 結構描述,則會為該參數在記憶體中建立 DiscoveryDocument

例外狀況

存取提供的 URL 已經傳回 HTTP 狀態碼,而不是傳回 OK

url 參數是有效 URL,但是沒有指向有效探索文件、服務描述或 XSD 結構描述。

範例

下列程式碼範例是 Web Form, DataGrid 會在 XML Web 服務探索期間填入 屬性中 Documents 檔的詳細資料,以及每個檔中找到的參考。 方法 PopulateGridDataGrid 以調用的結果 DiscoverAny 填入 ,後面接著呼叫 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;
        
        // Discover the URL for any discoverable documents. 
    doc = client.DiscoverAny(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
     ' Discover the URL for any discoverable documents. 
     doc = client.DiscoverAny(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 the DataGrid 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

備註

方法 DiscoverAny 會探索提供的 URL 是否為探索檔、服務描述或 XSD 架構。 如果已知 URL 只參考探索檔, Discover 可能會叫用 方法。

如果提供的 URL 指向有效的探索檔、XSD 架構或服務描述,則提供的 URL 上的探索檔會新增至 DocumentsReferences 集合。 當提供的 URL 參考 XSD 架構或服務描述 DiscoveryDocument 時,會在記憶體中建立 ,並新增至 DocumentsReferences 集合。 此外,探索檔內的參考會新增至 References 集合,但無法驗證以指向有效的探索檔。 若要確認參考指向有效的探索檔,請叫 ResolveAll 用 或 ResolveOneLevel 方法。

適用於