Share via


SchemaReference 類別

定義

表示探索 (Discovery) 文件中對 XML 結構描述定義 (XSD) 語言結構描述 (Schema) 的參考。 此類別無法獲得繼承。

public ref class SchemaReference sealed : System::Web::Services::Discovery::DiscoveryReference
public sealed class SchemaReference : System.Web.Services.Discovery.DiscoveryReference
type SchemaReference = class
    inherit DiscoveryReference
Public NotInheritable Class SchemaReference
Inherits DiscoveryReference
繼承
SchemaReference

範例

#using <System.dll>
#using <System.Xml.dll>
#using <System.Web.Services.dll>

using namespace System;
using namespace System::IO;
using namespace System::Net;
using namespace System::Xml;
using namespace System::Xml::Schema;
using namespace System::Web::Services::Discovery;
int main()
{
   try
   {
      
      // Reference the schema document.
      String^ myStringUrl = "c:\\Inetpub\\wwwroot\\dataservice.xsd";
      XmlSchema^ myXmlSchema;
      
      // Create the client protocol.
      DiscoveryClientProtocol^ myDiscoveryClientProtocol = gcnew DiscoveryClientProtocol;
      myDiscoveryClientProtocol->Credentials = CredentialCache::DefaultCredentials;
      
      //  Create a schema reference.
      SchemaReference^ mySchemaReferenceNoParam = gcnew SchemaReference;
      SchemaReference^ mySchemaReference = gcnew SchemaReference( myStringUrl );
      
      // Set the client protocol.
      mySchemaReference->ClientProtocol = myDiscoveryClientProtocol;
      
      // Access the default file name associated with the schema reference.
      Console::WriteLine( "Default filename is : {0}", mySchemaReference->DefaultFilename );
      
      // Access the namespace associated with schema reference class.
      Console::WriteLine( "Namespace is : {0}", SchemaReference::Namespace );
      FileStream^ myStream = gcnew FileStream( myStringUrl,FileMode::OpenOrCreate );
      
      // Read the document in a stream.
      mySchemaReference->ReadDocument( myStream );
      
      // Get the schema of referenced document.
      myXmlSchema = mySchemaReference->Schema;
      Console::WriteLine( "Reference is : {0}", mySchemaReference->Ref );
      Console::WriteLine( "Target namespace (default empty) is : {0}", mySchemaReference->TargetNamespace );
      Console::WriteLine( "URL is : {0}", mySchemaReference->Url );
      
      // Write the document in the stream.
      mySchemaReference->WriteDocument( myXmlSchema, myStream );
      myStream->Close();
      mySchemaReference = nullptr;
      
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( e );
   }

}
using System;
using System.IO;
using System.Net;
using System.Xml;
using System.Xml.Schema;
using System.Web.Services.Discovery;

public class SchemaReferenceClass
{
   public static void Main()
   {
      try
      {


         // Reference the schema document.
         string myStringUrl = "c:\\Inetpub\\wwwroot\\dataservice.xsd";
         XmlSchema myXmlSchema;

         // Create the client protocol.
         DiscoveryClientProtocol myDiscoveryClientProtocol =
             new DiscoveryClientProtocol();
         myDiscoveryClientProtocol.Credentials =
             CredentialCache.DefaultCredentials;

         //  Create a schema reference.
         SchemaReference mySchemaReferenceNoParam = new SchemaReference();

         SchemaReference mySchemaReference = new SchemaReference(myStringUrl);

         // Set the client protocol.
         mySchemaReference.ClientProtocol = myDiscoveryClientProtocol;

         // Access the default file name associated with the schema reference.
         Console.WriteLine("Default filename is : " +
             mySchemaReference.DefaultFilename);

         // Access the namespace associated with schema reference class.
         Console.WriteLine("Namespace is : " + SchemaReference.Namespace);

         FileStream myStream =
             new FileStream(myStringUrl,FileMode.OpenOrCreate);

         // Read the document in a stream.
         mySchemaReference.ReadDocument(myStream);

         // Get the schema of referenced document.
         myXmlSchema = mySchemaReference.Schema;

         Console.WriteLine("Reference is : " + mySchemaReference.Ref);

         Console.WriteLine("Target namespace (default empty) is : " +
             mySchemaReference.TargetNamespace);

         Console.WriteLine("URL is : " + mySchemaReference.Url);

         // Write the document in the stream.
         mySchemaReference.WriteDocument(myXmlSchema,myStream);

         myStream.Close();
         mySchemaReference = null;

      }
      catch (Exception e)
      {
         Console.WriteLine(e.ToString());
      }
   }
}
Imports System.IO
Imports System.Net
Imports System.Xml
Imports System.Xml.Schema
Imports System.Web.Services.Discovery

Public Module SchemaReferenceModule

   Public Sub Main()
      Try


         ' Reference the schema document.
         Dim myStringUrl As String = "c:\\Inetpub\\wwwroot\\dataservice.xsd"
         Dim myXmlSchema As XmlSchema

         ' Create the client protocol.
         Dim myDiscoveryClientProtocol As DiscoveryClientProtocol = _
             New DiscoveryClientProtocol()
         myDiscoveryClientProtocol.Credentials = _
             CredentialCache.DefaultCredentials

         ' Create a schema reference.
         Dim mySchemaReferenceNoParam As SchemaReference = New SchemaReference()

         Dim mySchemaReference As SchemaReference = _
             New SchemaReference(myStringUrl)

         ' Set the client protocol.
         mySchemaReference.ClientProtocol = myDiscoveryClientProtocol

         ' Access the default file name associated with the schema reference.
         Console.WriteLine("Default filename is : " & _
             mySchemaReference.DefaultFilename)

         ' Access the namespace associated with schema reference class.
         Console.WriteLine("Namespace is : " & SchemaReference.Namespace)

         Dim myStream As FileStream = _
             New FileStream(myStringUrl, FileMode.OpenOrCreate)

         ' Read the document in a stream.
         mySchemaReference.ReadDocument(myStream)

         ' Get the schema of the referenced document.
         myXmlSchema = mySchemaReference.Schema

         Console.WriteLine("Reference is : " & mySchemaReference.Ref)

         Console.WriteLine("Target namespace (default empty) is : " & _
             mySchemaReference.TargetNamespace)

         Console.WriteLine("URL is : " & mySchemaReference.Url)

         ' Write the document in the stream.
         mySchemaReference.WriteDocument(myXmlSchema, myStream)

         myStream.Close()
         mySchemaReference = Nothing
      Catch e As Exception

         Console.WriteLine(e.ToString)

      End Try

   End Sub
End Module

備註

XML Web 服務探索牽涉到探索指定的可用 XML Web 服務 URL。 URL 通常會指向探索檔,其通常副檔名為 a.disco。 探索檔包含 XML Web 服務存在相關資訊的參考。 這些參考可以參考服務描述、XSD 架構或其他探索檔。 這個類別代表 XSD 架構的參考。

在探索檔中,XSD 架構的參考包含在 XML 元素內 schemaRefschemaRefXML 元素具有 XML 命名空間和 ref 屬性。 XML 命名空間的值必須符合 Namespace 常數。 屬性的值 ref 會放在 屬性中 Ref

建構函式

SchemaReference()

使用預設值,初始化 SchemaReference 類別的新執行個體。

SchemaReference(String)

使用所提供的 URL 做為 XSD 結構描述參考,初始化 SchemaReference 類別的新執行個體。

欄位

Namespace

探索文件中的 XSD 結構描述參考的 XML 命名空間。

屬性

ClientProtocol

取得或設定 DiscoveryClientProtocol 的執行個體,其在探索程序中使用。

(繼承來源 DiscoveryReference)
DefaultFilename

取得儲存參考的 XSD 結構描述時要使用的預設檔名。

Ref

取得或設定參考的 XSD 結構描述的 URL。

Schema

取得 XmlSchema 物件,表示 XSD 結構描述。

TargetNamespace

取得或設定 XSD 結構描述的 targetNamespace XML 屬性。

Url

取得或設定結構描述參考的 URL。

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ReadDocument(Stream)

從傳遞的 Stream 讀取並傳回 XSD 結構描述。

Resolve()

下載 Url 中參考的文件,以解析參考的文件是否有效。

(繼承來源 DiscoveryReference)
Resolve(String, Stream)

解析參考的文件是否有效。

(繼承來源 DiscoveryReference)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)
WriteDocument(Object, Stream)

將傳遞的 XSD 結構描述寫入至傳遞的 Stream

適用於

另請參閱