DiscoveryClientProtocol.Discover(String) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
探索提供的 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 Web Service 探索在此處開始。
傳回
DiscoveryDocument,包含在所提供的 URL 處的 XML Web Service 探索結果。
例外狀況
存取提供的 URL 已經傳回 HTTP 狀態碼,而不是傳回 OK。
url
參數是有效 URL,但並未指向有效探索文件。
範例
下列程式碼範例是 Web Form,會填 DataGrid 入 屬性中 Documents 檔的詳細資料,以及 XML Web 服務探索期間在每個檔中找到的參考。 方法 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 方法的有效探索檔。