DiscoveryDocument 类

定义

表示发现文档。 此类不能被继承。

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

适用于

另请参阅