DiscoveryClientProtocol.Discover(String) Metod
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Identifierar den angivna URL:en för att avgöra om det är ett identifieringsdokument.
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
Parametrar
- url
- String
URL:en där XML-webbtjänstidentifieringen börjar.
Returer
En DiscoveryDocument som innehåller resultatet av XML-webbtjänstidentifiering på den angivna URL:en.
Undantag
Åtkomsten till den angivna URL:en returnerade en annan HTTP-statuskod än OK.
Parametern url är en giltig URL, men pekar inte på ett giltigt identifieringsdokument.
Exempel
Följande kodexempel är ett webbformulär som fyller i en DataGrid med information om dokumenten i Documents egenskapen tillsammans med de referenser som finns i varje dokument under IDENTIFIERING av XML-webbtjänster. Metoden PopulateGrid fyller DataGrid med resultatet från ett Discover anrop följt av ett anrop till 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
Kommentarer
Metoden Discover förväntar sig att den angivna URL:en är ett identifieringsdokument. Om URL:en refererar till en tjänstbeskrivning eller ett XML-schema genereras ett undantag. Om du vill identifiera ett XML-schema eller en tjänstbeskrivning anropar du DiscoverAny metoden.
Om den angivna URL:en pekar på ett giltigt identifieringsdokument läggs identifieringsdokumentet på den angivna URL:en till i Documents samlingen och References . Dessutom läggs referenser i identifieringsdokumentet till i References samlingen, men verifieras inte för att peka på giltiga identifieringsdokument. Om du vill verifiera referenserna pekar du på giltiga identifieringsdokument för att anropa ResolveAll metoderna eller ResolveOneLevel .