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)

public class DiscoveryClientProtocol : HttpWebClientProtocol

The DiscoveryClientProtocol type exposes the following members.

  NameDescription
Public methodDiscoveryClientProtocolInitializes a new instance of the DiscoveryClientProtocol class.
Top

  NameDescription
Public propertyAdditionalInformationGets information in addition to references found in the discovery document.
Public propertyAllowAutoRedirectGets or sets whether the client automatically follows server redirects. (Inherited from HttpWebClientProtocol.)
Protected propertyCanRaiseEventsGets a value indicating whether the component can raise an event. (Inherited from Component.)
Public propertyClientCertificatesGets the collection of client certificates. (Inherited from HttpWebClientProtocol.)
Public propertyConnectionGroupNameGets or sets the name of the connection group for the request. (Inherited from WebClientProtocol.)
Public propertyContainerGets the IContainer that contains the Component. (Inherited from Component.)
Public propertyCookieContainerGets or sets the collection of cookies. (Inherited from HttpWebClientProtocol.)
Public propertyCredentialsGets or sets security credentials for XML Web service client authentication. (Inherited from WebClientProtocol.)
Protected propertyDesignModeGets a value that indicates whether the Component is currently in design mode. (Inherited from Component.)
Public propertyDocumentsGets a collection of discovery documents.
Public propertyEnableDecompressionGets or sets a value that indicates whether decompression is enabled for this HttpWebClientProtocol. (Inherited from HttpWebClientProtocol.)
Public propertyErrorsGets a collection of exceptions that occurred during invocation of method from this class.
Protected propertyEventsGets the list of event handlers that are attached to this Component. (Inherited from Component.)
Public propertyPreAuthenticateGets or sets whether pre-authentication is enabled. (Inherited from WebClientProtocol.)
Public propertyProxyGets or sets proxy information for making an XML Web service request through a firewall. (Inherited from HttpWebClientProtocol.)
Public propertyReferencesA collection of references founds in resolved discovery documents.
Public propertyRequestEncodingThe Encoding used to make the client request to the XML Web service. (Inherited from WebClientProtocol.)
Public propertySiteGets or sets the ISite of the Component. (Inherited from Component.)
Public propertyTimeoutIndicates the time an XML Web service client waits for the reply to a synchronous XML Web service request to arrive (in milliseconds). (Inherited from WebClientProtocol.)
Public propertyUnsafeAuthenticatedConnectionSharingGets or sets a value that indicates whether connection sharing is enabled when the client uses NTLM authentication to connect to the Web server that hosts the XML Web service. (Inherited from HttpWebClientProtocol.)
Public propertyUrlGets or sets the base URL of the XML Web service the client is requesting. (Inherited from WebClientProtocol.)
Public propertyUseDefaultCredentialsGets or sets a value that indicates whether to set the Credentials property to the value of the CredentialCache.DefaultCredentials property. (Inherited from WebClientProtocol.)
Public propertyUserAgentGets or sets the value for the user agent header that is sent with each request. (Inherited from HttpWebClientProtocol.)
Top

  NameDescription
Public methodAbortCancels a request to an XML Web service method. (Inherited from WebClientProtocol.)
Protected methodCancelAsyncCancels an asynchronous call to an XML Web service method, unless the call has already completed. (Inherited from HttpWebClientProtocol.)
Public methodCreateObjRefCreates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Public methodDiscoverDiscovers the supplied URL to determine if it is a discovery document.
Public methodDiscoverAnyDiscovers the supplied URL to determine if it is a discovery document, service description or an XML Schema Definition (XSD) schema.
Public methodDispose()Releases all resources used by the Component. (Inherited from Component.)
Protected methodDispose(Boolean)Releases the unmanaged resources used by the Component and optionally releases the managed resources. (Inherited from Component.)
Public methodDownload(String)Downloads the discovery document at the supplied URL into a Stream object.
Public methodDownload(String, String)Downloads the discovery document at the supplied URL into a Stream object, setting the contentType parameter to the MIME encoding of the discovery document.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeReleases unmanaged resources and performs other cleanup operations before the Component is reclaimed by garbage collection. (Inherited from Component.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetLifetimeServiceRetrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected methodGetServiceReturns an object that represents a service provided by the Component or by its Container. (Inherited from Component.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodGetWebRequestCreates a WebRequest for the specified URI. (Inherited from HttpWebClientProtocol.)
Protected methodGetWebResponse(WebRequest)Returns a response from a synchronous request to an XML Web service method. (Inherited from HttpWebClientProtocol.)
Protected methodGetWebResponse(WebRequest, IAsyncResult)Returns a response from an asynchronous request to an XML Web service method. (Inherited from HttpWebClientProtocol.)
Public methodInitializeLifetimeServiceObtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public methodLoadExternals Obsolete. Instructs the DiscoveryClientProtocol object to load any external references.
Protected methodMemberwiseClone()Creates a shallow copy of the current Object. (Inherited from Object.)
Protected methodMemberwiseClone(Boolean)Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)
Public methodReadAllReads in a file containing a map of saved discovery documents populating the Documents and References properties, with discovery documents, XML Schema Definition (XSD) schemas, and service descriptions referenced in the file.
Public methodResolveAllResolves all references to discovery documents, XML Schema Definition (XSD) schemas, and service descriptions in the References property, as well as references found in referenced discovery documents.
Public methodResolveOneLevelResolves all references to discovery documents, XML Schema Definition (XSD) schemas and service descriptions in References, as well as references found in those discovery documents.
Public methodToStringReturns a String containing the name of the Component, if any. This method should not be overridden. (Inherited from Component.)
Public methodWriteAllWrites all discovery documents, XML Schema Definition (XSD) schemas, and Service Descriptions in the Documents property to the supplied directory and creates a file in that directory.
Top

  NameDescription
Public eventDisposedOccurs when the component is disposed by a call to the Dispose method. (Inherited from Component.)
Top

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 Windows Software Development Kit (SDK) ships the Web Services Discovery tool (Disco.exe) for discovering XML Web services within a command prompt. For more details, see [<topic://cpgrfwebservicesdiscoverytooldiscoexe>].

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.

<%@ Page Language="C#" Debug="true" %>

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

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

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


      }

      protected void PopulateGrid(DiscoveryClientProtocol client) 
      {
         DataTable dt = new DataTable();
         DataRow dr;

         dt.Columns.Add(new DataColumn("Discovery Document"));
         dt.Columns.Add(new DataColumn("References"));
         dt.Columns.Add(new DataColumn("Type"));


         foreach (DictionaryEntry entry in client.Documents) 
         {
                dr = dt.NewRow();
  		dr[0] = (string) entry.Key;
		dr[2] = entry.Value.GetType();
		dt.Rows.Add(dr);
		if (entry.Value is DiscoveryDocument)
		{
	  	  DiscoveryDocument discoDoc = (DiscoveryDocument) entry.Value;
		  foreach (DiscoveryReference discoref in discoDoc.References)
		  {
		    dr = dt.NewRow();
		    dr[1] = discoref.Url;
		    dr[2] = discoref.GetType();
		    dt.Rows.Add(dr);
		   }
		}
		
         }
        DataView dv = new DataView(dt);
	DiscoveryResultsGrid.DataSource = (ICollection) dv;
	DiscoveryResultsGrid.DataBind();

    }
  </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>

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

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