DiscoveryClientProtocol クラス

定義

プログラムによる XML Web サービス探索の呼び出しをサポートします。

public ref class DiscoveryClientProtocol : System::Web::Services::Protocols::HttpWebClientProtocol
public class DiscoveryClientProtocol : System.Web.Services.Protocols.HttpWebClientProtocol
type DiscoveryClientProtocol = class
    inherit HttpWebClientProtocol
Public Class DiscoveryClientProtocol
Inherits HttpWebClientProtocol
継承

次のコード例は、名前空間内System.Web.Services.Discoveryの他のクラスと共に クラスをDiscoveryClientProtocol使用して、プログラムによって XML Web サービス検出を呼び出す方法を示す Web フォームです。 このコード例では、、DiscoverAny、、DiscoverResolveOneLevelResolveAllReadAll、および WriteAll メソッドのDiscover使用を示します。

重要

この例には、ユーザー入力を受け付けるテキスト ボックスがあります。これにより、セキュリティが脆弱になる可能性があります。 既定では、ASP.NET Web ページによって、ユーザー入力にスクリプトまたは HTML 要素が含まれていないかどうかが検証されます。 詳細については、「スクリプトによる攻略の概要」を参照してください。

<%@ 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>
<%@ 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>

注釈

XML Web サービス検出は、使用可能な XML Web サービスを記述する 1 つ以上の関連ドキュメントを検索または検出するプロセスです。 XML Web サービス クライアントは、XML Web サービスの検出を通じて、特定の URL で使用可能な XML Web サービスとその使用方法について学習します。 XML Web サービスの検出は、ディレクトリ サービスを介して検出ドキュメントへの URL を既に取得している前提から機能しますが、提供される XML Web サービスの詳細はありません。 XML Web サービスの検出を使用すると、 に一覧表示されている XML Web サービスに関する詳細を特定の DiscoveryDocument URL で検出できます。

XML Web サービス クライアントは、 メソッドまたは DiscoverAny メソッドのいずれかに URL を指定することで、XML Web サービスの検出をDiscover開始します。 通常、この URL は探索ドキュメントを参照します。これは、プロパティに追加される 1 つ以上の XML Web サービスを記述するドキュメントを References 指します。 その時点で、そのドキュメントのみがダウンロードされ、XML Web サービスに関する有効な情報を参照するように検証されます。 ただし、この段階では、そのドキュメントに含まれる参照は検証されません。 代わりに、 プロパティに References 追加されます。 参照が有効であることを確認するには、 メソッドまたは ResolveOneLevel メソッドをResolveAll呼び出して、有効な参照ドキュメントを プロパティにDocuments追加します。 最後に、クライアントが検出結果をディスクに保存する場合は、 メソッドを WriteAll 呼び出します。

XML Web サービス検出へのプログラムによるアクセスが必要ない場合、Windows SDK には、コマンド プロンプト内で XML Web サービスを検出するための Web サービス検出ツール (Disco.exe) が付属しています。 詳細については、「 Web サービス検出ツール (Disco.exe)」を参照してください。

コンストラクター

DiscoveryClientProtocol()

DiscoveryClientProtocol クラスの新しいインスタンスを初期化します。

プロパティ

AdditionalInformation

探索ドキュメントで発見された参照に加えて、情報を取得します。

AllowAutoRedirect

クライアントがサーバーのリダイレクトに自動的に従うかどうかを取得または設定します。

(継承元 HttpWebClientProtocol)
CanRaiseEvents

コンポーネントがイベントを発生させることがきるかどうかを示す値を取得します。

(継承元 Component)
ClientCertificates

クライアント証明書のコレクションを取得します。

(継承元 HttpWebClientProtocol)
ConnectionGroupName

要求に対して使用する接続グループの名前を取得または設定します。

(継承元 WebClientProtocol)
Container

IContainer を含む Component を取得します。

(継承元 Component)
CookieContainer

クッキーのコレクションを取得または設定します。

(継承元 HttpWebClientProtocol)
Credentials

XML Web サービス クライアント認証のセキュリティ資格情報を取得または設定します。

(継承元 WebClientProtocol)
DesignMode

Component が現在デザイン モードかどうかを示す値を取得します。

(継承元 Component)
Documents

探索ドキュメントのコレクションを取得します。

EnableDecompression

この HttpWebClientProtocol の圧縮解除が有効かどうかを示す値を取得または設定します。

(継承元 HttpWebClientProtocol)
Errors

このクラスからメソッドを呼び出したときに発生した例外のコレクションを取得します。

Events

Component に結び付けられているイベント ハンドラーのリストを取得します。

(継承元 Component)
PreAuthenticate

事前認証を有効にするかどうかを取得または設定します。

(継承元 WebClientProtocol)
Proxy

ファイアウォールをとおして XML Web サービス要求を行うためのプロキシ情報を取得または設定します。

(継承元 HttpWebClientProtocol)
References

解決された探索ドキュメント内に見つかった参照のコレクション。

RequestEncoding

クライアントが XML Web サービスを要求するときに使用される Encoding

(継承元 WebClientProtocol)
Site

ComponentISite を取得または設定します。

(継承元 Component)
Timeout

同期的な XML Web サービスの要求に対する返答の受信を XML Web サービス クライアントが待機する時間 (ミリ秒単位) を示します。

(継承元 WebClientProtocol)
UnsafeAuthenticatedConnectionSharing

XML Web サービスをホストしている Web サービスに接続するときにクライアントが NTLM 認証を使用する場合、接続共有が有効になっているかどうかを示す値を取得または設定します。

(継承元 HttpWebClientProtocol)
Url

クライアントが要求している XML Web サービスのベース URL を取得または設定します。

(継承元 WebClientProtocol)
UseDefaultCredentials

Credentials プロパティを DefaultCredentials プロパティの値に設定するかどうかを示す値を取得または設定します。

(継承元 WebClientProtocol)
UserAgent

それぞれの要求と共に送信されるユーザー エージェント ヘッダーの値を取得または設定します。

(継承元 HttpWebClientProtocol)

メソッド

Abort()

XML Web サービス メソッドへの要求をキャンセルします。

(継承元 WebClientProtocol)
CancelAsync(Object)

呼び出しが完了済みの場合を除き、XML Web サービス メソッドの非同期呼び出しをキャンセルします。

(継承元 HttpWebClientProtocol)
CreateObjRef(Type)

リモート オブジェクトとの通信に使用するプロキシの生成に必要な情報をすべて格納しているオブジェクトを作成します。

(継承元 MarshalByRefObject)
Discover(String)

指定された URL を探索し、探索ドキュメントかどうかを判断します。

DiscoverAny(String)

指定した URL を探索して、この URL が探索ドキュメントであるか、サービスの説明であるか、または XML スキーマ定義 (XSD) スキーマであるかを判断します。

Dispose()

Component によって使用されているすべてのリソースを解放します。

(継承元 Component)
Dispose(Boolean)

Component によって使用されているアンマネージド リソースを解放し、オプションでマネージド リソースも解放します。

(継承元 Component)
Download(String)

指定された URL の探索ドキュメントを Stream オブジェクトにダウンロードします。

Download(String, String)

contentType パラメーターを探索ドキュメントの MIME エンコーディングに設定して、指定された URL の探索ドキュメントを Stream オブジェクトにダウンロードします。

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetLifetimeService()
古い.

対象のインスタンスの有効期間ポリシーを制御する、現在の有効期間サービス オブジェクトを取得します。

(継承元 MarshalByRefObject)
GetService(Type)

Component またはその Container で提供されるサービスを表すオブジェクトを返します。

(継承元 Component)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
GetWebRequest(Uri)

指定した URI に対する WebRequest を作成します。

(継承元 HttpWebClientProtocol)
GetWebResponse(WebRequest)

XML Web サービス メソッドへの同期要求から応答を返します。

(継承元 HttpWebClientProtocol)
GetWebResponse(WebRequest, IAsyncResult)

XML Web サービス メソッドへの非同期要求から応答を返します。

(継承元 HttpWebClientProtocol)
InitializeLifetimeService()
古い.

このインスタンスの有効期間ポリシーを制御する有効期間サービス オブジェクトを取得します。

(継承元 MarshalByRefObject)
LoadExternals()
古い.

DiscoveryClientProtocol オブジェクトに対して、外部参照を読み込むように指示します。

MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
MemberwiseClone(Boolean)

現在の MarshalByRefObject オブジェクトの簡易コピーを作成します。

(継承元 MarshalByRefObject)
ReadAll(String)

保存された探索ドキュメントのマップが格納されているファイルを読み取ります。その探索ドキュメントには、そのファイルが参照している探索ドキュメント、XML スキーマ定義 (XSD) スキーマ、およびサービスの説明を持つ Documents プロパティと References プロパティが読み込まれています。

ResolveAll()

References プロパティ内の探索ドキュメント、XML スキーマ定義 (XSD) スキーマ、およびサービスの説明へのすべての参照と同様に、参照される探索ドキュメント内で見つかった参照も解決します。

ResolveOneLevel()

References 内の探索ドキュメント、XML スキーマ定義 (XSD) スキーマ、およびサービスの説明へのすべての参照と同様に探索ドキュメントで見つかった参照も解決します。

ToString()

Component の名前 (存在する場合) を格納する String を返します。 このメソッドはオーバーライドできません。

(継承元 Component)
WriteAll(String, String)

Documents プロパティの探索ドキュメント、XML スキーマ定義 (XSD) スキーマ、およびサービスの説明のすべてを指定されたディレクトリに書き込み、そのディレクトリにファイルを作成します。

イベント

Disposed

Dispose() メソッドの呼び出しによってコンポーネントが破棄されるときに発生します。

(継承元 Component)

適用対象

こちらもご覧ください