共用方式為


DiscoveryClientProtocol.References 屬性

定義

參考的集合會在已解析的探索文件中找到。

public:
 property System::Web::Services::Discovery::DiscoveryClientReferenceCollection ^ References { System::Web::Services::Discovery::DiscoveryClientReferenceCollection ^ get(); };
public System.Web.Services.Discovery.DiscoveryClientReferenceCollection References { get; }
member this.References : System.Web.Services.Discovery.DiscoveryClientReferenceCollection
Public ReadOnly Property References As DiscoveryClientReferenceCollection

屬性值

探索到的參考之 DiscoveryClientReferenceCollection

範例

下列程式代碼範例是 Web Form,會填 DataGrid 入 XML Web 服務探索期間所探索屬性中 References 參考的詳細數據。 方法 PopulateGrid 會將 DataGrid 在呼叫 DiscoverAny中找到的參考填入 。

重要

這個範例有一個可接受使用者輸入的文字方塊,這可能會造成安全性威脅。 根據預設,ASP.NET Web 網頁會驗證使用者輸入未包含指令碼或 HTML 項目。 如需詳細資訊,請參閱 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;

        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);
        }
        catch ( Exception e2) 
        {
          DiscoveryResultsGrid.Columns.Clear();
          Status.Text = e2.Message;
        }
    // If the discovered document contained, references display them in a data grid.
        if (client.References.Count > 0)
        PopulateGrid(client);
   }

      protected void PopulateGrid(DiscoveryClientProtocol client) 
      {
         DataTable dt = new DataTable();
         DataRow dr;
 
         dt.Columns.Add(new DataColumn("Reference") );
         dt.Columns.Add(new DataColumn("Type") );

     // Iterate over the references in the discovered document, displaying their type.
         foreach (DictionaryEntry entry in client.References) 
         {
                dr = dt.NewRow();
        dr[0] = (string) entry.Key;
        dr[1] = entry.Value.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>

    <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

      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)

       Catch e2 As Exception
          DiscoveryResultsGrid.Columns.Clear()
          Status.Text = e2.Message
       End Try

       ' If the discovered document contained references, display them in a data grid.
       If (client.References.Count > 0) Then
            'populate our Grid with the discovery results
        PopulateGrid(client)
       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("Reference") )
    dt.Columns.Add(new DataColumn("Type") )

    Dim entry As DictionaryEntry
     
    ' Iterate over the references in the discovered document, displaying their type.
    For Each entry in client.References
       dr = dt.NewRow()
       dr(0) = entry.Key
       dr(1) = entry.Value.GetType()
       dt.Rows.Add(dr)
    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>

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

備註

在叫用DiscoverResolveAllDiscoverAnyResolveOneLevel 方法期間,會References填入集合。 在叫 Discover 用 和 DiscoverAny 方法期間,如果提供的 URL 是有效的探索檔,則會將該檔新增至 References 集合,以及探索檔中找到的參考。 在叫用 和 DiscoverAny 方法期間新增的Discover參考不一定是有效的探索檔。 在叫用 ResolveAll 集合內的 ReferencesResolveOneLevel 參考期間,會驗證為有效的探索檔。 如果它們有效且包含參考,它們也會新增至 References 集合。

適用於