次の方法で共有


DiscoveryDocument.Write メソッド

DiscoveryDocument を渡されたオブジェクトに書き込みます。

オーバーロードの一覧

渡された StreamDiscoveryDocument を書き込みます。

[Visual Basic] Overloads Public Sub Write(Stream)

[C#] public void Write(Stream);

[C++] public: void Write(Stream*);

[JScript] public function Write(Stream);

渡された TextWriterDiscoveryDocument を書き込みます。

[Visual Basic] Overloads Public Sub Write(TextWriter)

[C#] public void Write(TextWriter);

[C++] public: void Write(TextWriter*);

[JScript] public function Write(TextWriter);

渡された XmlWriterDiscoveryDocument を書き込みます。

[Visual Basic] Overloads Public Sub Write(XmlWriter)

[C#] public void Write(XmlWriter);

[C++] public: void Write(XmlWriter*);

[JScript] public function Write(XmlWriter);

使用例

[Visual Basic, C#, C++] 探索ドキュメントを XmlTextWriter に書き込むコード例を次に示します。

[Visual Basic, C#, C++] メモ   ここでは、Write のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。

 
' Create a DiscoveryDocument.
Dim myDiscoveryDocument As New DiscoveryDocument()

' Create an XmlTextReader with the sample file.
Dim myXmlTextReader As _
    New XmlTextReader("https://localhost/example_Write2_vb.disco")

' Read the given XmlTextReader.
myDiscoveryDocument = DiscoveryDocument.Read(myXmlTextReader)

Dim myFileStream As _
    New FileStream("log.txt", FileMode.OpenOrCreate, FileAccess.Write)
Dim myStreamWriter As New StreamWriter(myFileStream)

Dim myXmlTextWriter As New XmlTextWriter(myStreamWriter)
myDiscoveryDocument.Write(myXmlTextWriter)

myXmlTextWriter.Flush()
myXmlTextWriter.Close()

' Display the contents of the DiscoveryDocument on 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 beginning.
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()

[C#] 
// Create a DiscoveryDocument.
DiscoveryDocument myDiscoveryDocument = new DiscoveryDocument();

// Create an XmlTextReader with the sample file.
XmlTextReader myXmlTextReader = new
   XmlTextReader( "https://localhost/example_Write2_cs.disco" );

// Read the given XmlTextReader.
myDiscoveryDocument = DiscoveryDocument.Read( myXmlTextReader );

FileStream myFileStream = new
   FileStream( "log.txt", FileMode.OpenOrCreate, FileAccess.Write );
StreamWriter myStreamWriter = new StreamWriter( myFileStream );


XmlTextWriter myXmlTextWriter = new XmlTextWriter( myStreamWriter );
myDiscoveryDocument.Write( myXmlTextWriter );


myXmlTextWriter.Flush();
myXmlTextWriter.Close();

// Display the contents of the DiscoveryDocument on the console.
FileStream myFileStream1 = new
   FileStream( "log.txt", FileMode.OpenOrCreate, FileAccess.Read );
StreamReader myStreamReader = new StreamReader( myFileStream1 );

// Set the file pointer to the beginning.
myStreamReader.BaseStream.Seek(0, SeekOrigin.Begin);
Console.WriteLine( "The contents of the DiscoveryDocument are:" );
while ( myStreamReader.Peek() > -1 )
{
   Console.WriteLine( myStreamReader.ReadLine() );
}
myStreamReader.Close();

[C++] 
// Create a DiscoveryDocument.
DiscoveryDocument* myDiscoveryDocument = new DiscoveryDocument();

// Create an XmlTextReader with the sample file.
XmlTextReader* myXmlTextReader = 
    new XmlTextReader(S"https://localhost/example_Write2_cs.disco");

// Read the given XmlTextReader.
myDiscoveryDocument = DiscoveryDocument::Read(myXmlTextReader);

FileStream* myFileStream = new FileStream(S"log.txt", 
    FileMode::OpenOrCreate, FileAccess::Write);
StreamWriter* myStreamWriter = new StreamWriter(myFileStream);

XmlTextWriter* myXmlTextWriter = new XmlTextWriter(myStreamWriter);
myDiscoveryDocument->Write(myXmlTextWriter);

myXmlTextWriter->Flush();
myXmlTextWriter->Close();

// Display the contents of the DiscoveryDocument on the console.
FileStream* myFileStream1 = new 
    FileStream(S"log.txt", FileMode::OpenOrCreate, FileAccess::Read);
StreamReader* myStreamReader = new StreamReader(myFileStream1);

// Set the file pointer to the beginning.
myStreamReader->BaseStream -> Seek(0, SeekOrigin::Begin);
Console::WriteLine(S"The contents of the DiscoveryDocument are: ");
while (myStreamReader->Peek() > -1)
   Console::WriteLine(myStreamReader->ReadLine());
myStreamReader->Close();

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

参照

DiscoveryDocument クラス | DiscoveryDocument メンバ | System.Web.Services.Discovery 名前空間