This documentation is archived and is not being maintained.

DiscoveryDocument.Read Method (TextReader)

Reads and returns a DiscoveryDocument from the passed TextReader.

Namespace: System.Web.Services.Discovery
Assembly: System.Web.Services (in system.web.services.dll)

public static DiscoveryDocument Read (
	TextReader reader
)
public static DiscoveryDocument Read (
	TextReader reader
)
public static function Read (
	reader : TextReader
) : DiscoveryDocument
Not applicable.

Parameters

reader

The TextReader from which to read the DiscoveryDocument.

Return Value

A DiscoveryDocument containing the contents of a discovery document from the passed TextReader.

The following code example reads the discovery document from " http://localhost/example_Write2_cs.vsdisco " into a XmlTextReader.

// Create a DiscoveryDocument.
DiscoveryDocument myDiscoveryDocument = new DiscoveryDocument();

// Create an XmlTextReader with the sample file.
XmlTextReader myXmlTextReader = new
   XmlTextReader( "http://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();

// Create a DiscoveryDocument.
DiscoveryDocument myDiscoveryDocument = new DiscoveryDocument();

// Create an XmlTextReader with the sample file.
XmlTextReader myXmlTextReader = 
    new XmlTextReader("http://localhost/example_Write2_jsl.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.get_BaseStream().Seek(0, SeekOrigin.Begin);
Console.WriteLine("The contents of the DiscoveryDocument are:");
while (myStreamReader.Peek() > -1) {
    Console.WriteLine(myStreamReader.ReadLine());
}
myStreamReader.Close();

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0
Show: