Export (0) Print
Expand All

DiscoveryClientProtocol Class

Provides support for programmatically invoking XML Web services discovery.

Namespace: System.Web.Services.Discovery
Assembly: System.Web.Services (in system.web.services.dll)

'Declaration
Public Class DiscoveryClientProtocol
	Inherits HttpWebClientProtocol
'Usage
Dim instance As DiscoveryClientProtocol

public class DiscoveryClientProtocol extends HttpWebClientProtocol
public class DiscoveryClientProtocol extends HttpWebClientProtocol
Not applicable.

XML Web service discovery is the process of locating, or discovering, one or more related documents that describe available XML Web services. It is through XML Web services discovery that XML Web service clients learn about the available XML Web services at a given URL and how to use them. XML Web services discovery works from the premise that you have already obtained the URL to a discovery document, possibly through a directory service, such as http://uddi.microsoft.com, however, you do not have the details about the XML Web services offered. Through XML Web services discovery, you can discover the details about the XML Web services listed in a DiscoveryDocument at a specific URL.

An XML Web service client starts XML Web services discovery by supplying a URL to either the Discover or DiscoverAny methods. Typically, this URL refers to a discovery document, which in turn refers to documents that describe one or more XML Web services, which are added to the References property. At that point, only that document is downloaded and verified to point to valid information about XML Web services. However, the references contained in that document are not verified at this stage. Instead they are added to the References property. To verify that the references are valid, invoke the ResolveAll or ResolveOneLevel methods, which add valid referenced documents to the Documents property. Last, if a client wants to save the discovery results to disk, invoke the WriteAll method.

If programmatic access to XML Web services discovery is not needed, the .NET Framework SDK ships the Web Services Discovery tool (Disco.exe) for discovering XML Web services within a command prompt. For more details, see Web Services Discovery Tool (Disco.exe).

The following code example is a Web Form demonstrating how to use the DiscoveryClientProtocol class together with the other classes in the System.Web.Services.Discovery namespace to programmatically invoke XML Web services discovery. The code example demonstrates using the Discover, DiscoverAny, Discover, ResolveAll, ResolveOneLevel, ReadAll and WriteAll methods.

Security noteSecurity Note:

This example has a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see Script Exploits Overview (Visual Studio).

<%@ Page Language="VB" Debug="true" %>

<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Web.Services.Discovery" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.Data" %>

<HTML>
<HEAD>
   <SCRIPT RUNAT="SERVER">
   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
        ' Check to see whether the user wanted to read in existing discovery results.
	If (DiscoverMode.Value = "ReadAll") Then
	   Dim results As DiscoveryClientResultCollection 
           results = client.ReadAll(Path.Combine(DiscoDir.Text,"results.discomap"))
	   SaveMode.Value = "NoSave"						
	Else
	   ' Check to see whether the user user wants the capability to discover any kind of discoverable document.
           If (DiscoverMode.Value = "DiscoverAny") Then
	     doc = client.DiscoverAny(sourceUrl)
           Else
	     ' Discover only discovery documents, which might contain references to other types of discoverable documents. 
   	     doc = client.Discover(sourceUrl)
	   End If
           
           ' Check to see whether the user wants to resolve all possible references from the supplied URL.
 	   If (ResolveMode.Value = "ResolveAll") Then
	      client.ResolveAll()
           ' Check to see whether the user wants to resolve references nested more than one level deep.
	   ElseIf (ResolveMode.Value = "ResolveOneLevel")  Then
              client.ResolveOneLevel()
	   Else
  	      Status.Text = String.Empty
           End If
	End If
            
       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

       ' If the user also asked to have the results saved to the Web server, do so.	    
       If (SaveMode.Value = "Save") Then
	  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 If                             

      End Sub
      Public Sub PopulateGrid(client As DiscoveryClientProtocol) 
         Dim dt As DataTable = new DataTable()
         Dim dr AS DataRow 
 
         dt.Columns.Add(new DataColumn("Discovery Document") )
         dt.Columns.Add(new DataColumn("References") )
         dt.Columns.Add(new DataColumn("Type") )

	 Dim entry As DictionaryEntry
         For Each entry in client.Documents
            dr = dt.NewRow()
 	    dr(0) = entry.Key
 	    dr(2) = entry.Value.GetType()
 	    dt.Rows.Add(dr)
	    If TypeOf entry.Value Is DiscoveryDocument Then
	       Dim discoDoc As DiscoveryDocument = entry.Value
	       Dim discoref As DiscoveryReference
	       For Each discoref in discoDoc.References
		  dr = dt.NewRow()
		  dr(1) = discoref.Url
		  dr(2) = discoref.GetType()
		  dt.Rows.Add(dr)
	       Next
	    End If   
	Next 	
         
        Dim dv As DataView = new DataView(dt)
	DiscoveryResultsGrid.DataSource = dv
	DiscoveryResultsGrid.DataBind()
     End Sub
  </SCRIPT>
  </HEAD> 
  <BODY>
	<H3> <p align="center"> Discovery Class Sample </p> </H3>
        <FORM RUNAT="SERVER">

	<hr>	
        Enter the URL to discover:
        <asp:textbox id=DiscoURL Columns=60 runat="SERVER" /><p>

       Discovery Mode:
       <select id="DiscoverMode" size=1 runat="SERVER">
	     <option Value="DiscoverAny">Discover any of the discovery types</option>
             <option Value="Discover">Discover just discovery documents</option>
             <option Value="ReadAll">Read in saved discovery results</option>
	</select> <p>

       Resolve References Mode:
       <select id="ResolveMode" size=1 runat="SERVER">
	      <option Value="ResolveAll">Resolve all references</option>
             <option Value="ResolveOneLevel">Resolve references only in discovery documents within the supplied URL</option>
             <option Value="ResolveNone">Do not resolve references</option>
	</select> <p>
		
       Save Results Mode:
	<select id="SaveMode" size=1 runat="SERVER">
	      <option Value="NoSave">Do not save any of the discovery documents found locally</option>
             <option Value="Save">Save the discovery documents found locally</option>
      	</select> <p>
        Enter the directory to Read/Save the Discovery results:
        <asp:textbox id=DiscoDir runat="SERVER" /> <p>


	<p align="center"> <asp:Button id=Discover Text="Discover!" onClick="Discover_Click" runat="SERVER"/> </p><p>

        <hr>
        <asp:label id="Status" runat="SERVER" /><p>
     <asp:DataGrid id="DiscoveryResultsGrid"
           BorderColor="black"
           BorderWidth="1"
           CellPadding="3"
           AutoGenerateColumns="true"
           runat="server">

         <HeaderStyle BackColor="DarkBlue" ForeColor="White">
         </HeaderStyle>

         <AlternatingItemStyle BackColor="LightYellow">
         </AlternatingItemStyle>

     </asp:DataGrid>
        </FORM>
  </BODY>

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2015 Microsoft