Export (0) Print
Expand All

DiscoveryClientProtocol.DiscoverAny Method

Discovers the supplied URL to determine if it is a discovery document, service description or an XML Schema Definition (XSD) schema.

[Visual Basic]
Public Function DiscoverAny( _
   ByVal url As String _
) As DiscoveryDocument
[C#]
public DiscoveryDocument DiscoverAny(
 string url
);
[C++]
public: DiscoveryDocument* DiscoverAny(
 String* url
);
[JScript]
public function DiscoverAny(
   url : String
) : DiscoveryDocument;

Parameters

url
The URL where XML Web services discovery begins.

Return Value

A DiscoveryDocument containing the results of XML Web services discovery at the supplied URL. If the url parameter refers to a service description or an XSD Schema, a DiscoveryDocument is created in memory for it.

Exceptions

Exception Type Condition
WebException Accessing the supplied URL returned an HTTP status code other than OK.
InvalidOperationException The url parameteris a valid URL, but does not point to a valid discovery document, service description, or XSD schema.

Remarks

The DiscoverAny method discovers whether the supplied URL is a discovery document, service description or XSD schema. If it is known that the URL only refers to a discovery document, the Discover method might be invoked.

If the supplied URL points to a valid discovery document, XSD schema, or service description, the discovery document at the supplied URL is added to the Documents and References collections. When the supplied URL refers to an XSD schema or Service Description a DiscoveryDocument is created in memory and added to the Documents and References collections. Additionally, references within the discovery document are added to the References collection, but not verified to point to valid discovery documents. To verify that references point to valid discovery documents, invoke the ResolveAll or ResolveOneLevel methods.

Example

[Visual Basic, C#] The following code example is a Web Form that populates a DataGrid with the details about the documents in the Documents property together with the references found in each document during an XML Web services discovery. The PopulateGrid method fills the DataGrid with the results from a DiscoverAny invocation followed by a call to ResolveAll.

[Visual Basic] 
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

[C#] 
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>";
  }

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

DiscoveryClientProtocol Class | DiscoveryClientProtocol Members | System.Web.Services.Discovery Namespace

Show:
© 2015 Microsoft