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

XML Web services 发现开始位置的 URL。

返回

DiscoveryDocument,它包含所提供 URL 处的 XML Web services 发现的结果。

例外

访问所提供的 URL 返回了一个 HTTP 状态代码而不是 OK

url 参数是有效的 URL,但未指向有效的发现文档。

示例

下面的代码示例是一个 Web 窗体,它使用 有关 属性中的Documents文档的详细信息以及 XML Web 服务发现期间在每个文档中找到的引用填充 DataGrid 。 方法PopulateGrid使用调用的结果Discover填充 ,DataGrid然后调用 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 处的发现文档将添加到 DocumentsReferences 集合中。 此外,发现文档中的引用将添加到集合中 References ,但未验证是否指向有效的发现文档。 若要验证引用,请指向有效的发现文档以调用 ResolveAllResolveOneLevel 方法。

适用于