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

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

返回

DiscoveryDocument,它包含所提供 URL 处的 XML Web services 发现的结果。 如果 url 参数引用服务说明或 XSD 架构,则在内存中为它创建 DiscoveryDocument

例外

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

url 参数是有效的 URL,但未指向有效的发现文档、服务说明或 XSD 架构。

示例

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

适用于