DiscoveryDocument 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
表示探索 (Discovery) 文件。 此類別無法獲得繼承。
public ref class DiscoveryDocument sealed
public sealed class DiscoveryDocument
type DiscoveryDocument = class
Public NotInheritable Class DiscoveryDocument
- 繼承
-
DiscoveryDocument
範例
下列程式碼範例會使用 Read 從檔案讀取探索檔,並使用 方法將它寫回檔案 Write 。
#using <System.Xml.dll>
#using <System.Web.Services.dll>
using namespace System;
using namespace System::Xml;
using namespace System::IO;
using namespace System::Web::Services::Discovery;
using namespace System::Collections;
int main()
{
try
{
// Create an Object* of the 'DiscoveryDocument'.
DiscoveryDocument^ myDiscoveryDocument = gcnew DiscoveryDocument;
// Create an XmlTextReader with the sample file.
XmlTextReader^ myXmlTextReader = gcnew XmlTextReader( "http://localhost/example_cs.disco" );
// Read the given XmlTextReader.
myDiscoveryDocument = DiscoveryDocument::Read( myXmlTextReader );
// Write the DiscoveryDocument into the 'TextWriter'.
FileStream^ myFileStream = gcnew FileStream( "log.txt",FileMode::OpenOrCreate,FileAccess::Write );
StreamWriter^ myStreamWriter = gcnew StreamWriter( myFileStream );
myDiscoveryDocument->Write( myStreamWriter );
myStreamWriter->Flush();
myStreamWriter->Close();
// Display the contents of the DiscoveryDocument onto the console.
FileStream^ myFileStream1 = gcnew FileStream( "log.txt",FileMode::OpenOrCreate,FileAccess::Read );
StreamReader^ myStreamReader = gcnew StreamReader( myFileStream1 );
// Set the file pointer to the begin.
myStreamReader->BaseStream->Seek( 0, SeekOrigin::Begin );
Console::WriteLine( "The contents of the DiscoveryDocument are-" );
while ( myStreamReader->Peek() > -1 )
{
Console::WriteLine( myStreamReader->ReadLine() );
}
myStreamReader->Close();
}
catch ( Exception^ e )
{
Console::WriteLine( "Exception raised : {0}", e->Message );
}
}
using System;
using System.Xml;
using System.IO;
using System.Web.Services.Discovery;
using System.Collections;
public class DiscoveryDocument_Example
{
static void Main()
{
try
{
// Create an object of the 'DiscoveryDocument'.
DiscoveryDocument myDiscoveryDocument = new DiscoveryDocument();
// Create an XmlTextReader with the sample file.
XmlTextReader myXmlTextReader = new
XmlTextReader( "http://localhost/example_cs.disco" );
// Read the given XmlTextReader.
myDiscoveryDocument = DiscoveryDocument.Read( myXmlTextReader );
// Write the DiscoveryDocument into the 'TextWriter'.
FileStream myFileStream = new
FileStream( "log.txt", FileMode.OpenOrCreate, FileAccess.Write );
StreamWriter myStreamWriter = new StreamWriter( myFileStream );
myDiscoveryDocument.Write( myStreamWriter );
myStreamWriter.Flush();
myStreamWriter.Close();
// Display the contents of the DiscoveryDocument onto the console.
FileStream myFileStream1 = new
FileStream( "log.txt", FileMode.OpenOrCreate, FileAccess.Read );
StreamReader myStreamReader = new StreamReader( myFileStream1 );
// Set the file pointer to the begin.
myStreamReader.BaseStream.Seek(0, SeekOrigin.Begin);
Console.WriteLine( "The contents of the DiscoveryDocument are-" );
while ( myStreamReader.Peek() > -1 )
{
Console.WriteLine( myStreamReader.ReadLine() );
}
myStreamReader.Close();
}
catch( Exception e )
{
Console.WriteLine( "Exception raised : {0}", e.Message);
}
}
}
Imports System.Xml
Imports System.IO
Imports System.Web.Services.Discovery
Imports System.Collections
Public Class DiscoveryDocument_Example
Shared Sub Main()
Try
' Create an object of the 'DiscoveryDocument'.
Dim myDiscoveryDocument As New DiscoveryDocument()
' Create an XmlTextReader with the sample file.
Dim myXmlTextReader As New XmlTextReader("http://localhost/example_vb.disco")
' Read the given XmlTextReader.
myDiscoveryDocument = DiscoveryDocument.Read(myXmlTextReader)
' Write the DiscoveryDocument into the 'TextWriter'.
Dim myFileStream As New FileStream("log.txt", FileMode.OpenOrCreate, FileAccess.Write)
Dim myStreamWriter As New StreamWriter(myFileStream)
myDiscoveryDocument.Write(myStreamWriter)
myStreamWriter.Flush()
myStreamWriter.Close()
' Display the contents of the DiscoveryDocument onto the console.
Dim myFileStream1 As New FileStream("log.txt", FileMode.OpenOrCreate, FileAccess.Read)
Dim myStreamReader As New StreamReader(myFileStream1)
' Set the file pointer to the begin.
myStreamReader.BaseStream.Seek(0, SeekOrigin.Begin)
Console.WriteLine("The contents of the DiscoveryDocument are-")
While myStreamReader.Peek() > - 1
Console.WriteLine(myStreamReader.ReadLine())
End While
myStreamReader.Close()
Catch e As Exception
Console.WriteLine("Exception raised : {0}", e.Message.ToString())
End Try
End Sub
End Class
備註
XML Web 服務探索牽涉到在 URL 中探索可用的 XML Web 服務。 URL 通常會指向探索檔,其通常副檔名為 .disco。 探索檔是 XML 檔,包含 XML Web 服務存在相關資訊的參考,例如服務描述、XML 架構定義 (XSD) 語言架構或其他探索檔。 這個類別代表探索檔的內容;其中 屬性 References 包含探索檔內所包含的參考清單。
建構函式
DiscoveryDocument() |
初始化 DiscoveryDocument 類別的新執行個體。 |
欄位
Namespace |
探索文件的探索 XML 項目的命名空間。 |
屬性
References |
內含於探索文件的參考清單。 |
方法
CanRead(XmlReader) |
傳回值,指出傳遞的 XmlReader 是否可還原序列化為 DiscoveryDocument。 |
Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
GetHashCode() |
做為預設雜湊函式。 (繼承來源 Object) |
GetType() |
取得目前執行個體的 Type。 (繼承來源 Object) |
MemberwiseClone() |
建立目前 Object 的淺層複製。 (繼承來源 Object) |
Read(Stream) |
從傳遞的 DiscoveryDocument 讀取並傳回 Stream。 |
Read(TextReader) |
從傳遞的 DiscoveryDocument 讀取並傳回 TextReader。 |
Read(XmlReader) |
從傳遞的 DiscoveryDocument 讀取並傳回 XmlReader。 |
ToString() |
傳回代表目前物件的字串。 (繼承來源 Object) |
Write(Stream) |
將這個 DiscoveryDocument 寫入至傳遞的 Stream。 |
Write(TextWriter) |
將這個 DiscoveryDocument 寫入至傳遞的 TextWriter。 |
Write(XmlWriter) |
將這個 DiscoveryDocument 寫入至傳遞的 XmlWriter。 |