Import 類別

定義

將 XML 命名空間 (Namespace) 與文件位置相關聯。 此類別無法獲得繼承。

public ref class Import sealed : System::Web::Services::Description::DocumentableItem
public sealed class Import : System.Web.Services.Description.DocumentableItem
[System.Web.Services.Configuration.XmlFormatExtensionPoint("Extensions")]
public sealed class Import : System.Web.Services.Description.DocumentableItem
type Import = class
    inherit DocumentableItem
[<System.Web.Services.Configuration.XmlFormatExtensionPoint("Extensions")>]
type Import = class
    inherit DocumentableItem
Public NotInheritable Class Import
Inherits DocumentableItem
繼承
屬性

範例

下列範例顯示可建立 類別新實例的使用者 Import 定義方法。

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

using namespace System;
using namespace System::Web::Services::Description;
using namespace System::Collections;
using namespace System::Xml;

// Creates an Import object with namespace and location.
Import^ CreateImport( String^ targetNamespace, String^ targetlocation )
{
   Import^ myImport = gcnew Import;
   myImport->Location = targetlocation;
   myImport->Namespace = targetNamespace;
   return myImport;
}

void PrintImportCollection( String^ fileName_wsdl )
{
   // Read import collection properties from generated WSDL file.
   ServiceDescription^ myServiceDescription1 = ServiceDescription::Read( fileName_wsdl );
   ImportCollection^ myImportCollection = myServiceDescription1->Imports;
   Console::WriteLine( "Enumerating Import Collection for file ' {0}'...", fileName_wsdl );
   
   // Print Import properties to console.
   for ( int i = 0; i < myImportCollection->Count; ++i )
   {
      Console::WriteLine( "Namespace : {0}", myImportCollection[ i ]->Namespace );
      Console::WriteLine( "Location  : {0}", myImportCollection[ i ]->Location );
      Console::WriteLine( "ServiceDescription  : {0}", myImportCollection[ i ]->ServiceDescription->Name );
   }
}

int main()
{
   Console::WriteLine( "Import Sample" );
   
   ServiceDescription^ myServiceDescription = ServiceDescription::Read( "StockQuote_cpp.wsdl" );
   myServiceDescription->Imports->Add( CreateImport( "http://localhost/stockquote/schemas", "http://localhost/stockquote/stockquote_cpp.xsd" ) );

   // Save the ServiceDescripition to an external file.
   myServiceDescription->Write( "StockQuote_cpp.wsdl" );
   Console::WriteLine( "document 'StockQuote_cpp.wsdl'" );
   
   // Print the import collection to the console.
   PrintImportCollection( "StockQuote_cpp.wsdl" );
   
   myServiceDescription = ServiceDescription::Read( "StockQuoteService_cpp.wsdl" );
   myServiceDescription->Imports->Insert( 0, CreateImport( "http://localhost/stockquote/definitions", "http://localhost/stockquote/stockquote_cpp.wsdl" ) );

   // Save the ServiceDescripition to an external file.
   myServiceDescription->Write( "StockQuoteService_cs::wsdl" );
   Console::WriteLine( "" );
   Console::WriteLine( "document 'StockQuoteService_cpp.wsdl'" );
   
   //Print the import collection to the console.
   PrintImportCollection( "StockQuoteService_cpp.wsdl" );
}
using System;
using System.Web.Services.Description;
using System.Collections;
using System.Xml;

class MySample
{
   public static void Main()
   {
      Console.WriteLine("Import Sample");
      ServiceDescription myServiceDescription =
         ServiceDescription.Read("StockQuote_cs.wsdl");
      myServiceDescription.Imports.Add(
         CreateImport("http://localhost/stockquote/schemas",
         "http://localhost/stockquote/stockquote_cs.xsd"));
      // Save the ServiceDescripition to an external file.
      myServiceDescription.Write("StockQuote_cs.wsdl");
      Console.WriteLine(
         "Successfully added import to WSDL document 'StockQuote_cs.wsdl'");

      // Print the import collection to the console.
      PrintImportCollection("StockQuote_cs.wsdl");
      myServiceDescription =
         ServiceDescription.Read("StockQuoteService_cs.wsdl");
      myServiceDescription.Imports.Insert(
         0,CreateImport("http://localhost/stockquote/definitions",
         "http://localhost/stockquote/stockquote_cs.wsdl"));
      // Save the ServiceDescripition to an external file.
      myServiceDescription.Write("StockQuoteService_cs.wsdl");
      Console.WriteLine("");
      Console.WriteLine("Successfully added import to WSDL " +
         "document 'StockQuoteService_cs.wsdl'");

      //Print the import collection to the console.
      PrintImportCollection("StockQuoteService_cs.wsdl");
   }
   // Creates an Import object with namespace and location.
   public static Import CreateImport(string targetNamespace,
      string targetlocation)
   {
      Import myImport = new Import();
      myImport.Location = targetlocation;
      myImport.Namespace = targetNamespace;
      return myImport;
   }

   public static void PrintImportCollection(string fileName_wsdl)
   {
      // Read import collection properties from generated WSDL file.
      ServiceDescription myServiceDescription1 =
         ServiceDescription.Read(fileName_wsdl);
      ImportCollection myImportCollection = myServiceDescription1.Imports;
      Console.WriteLine("Enumerating Import Collection for file '" +
         fileName_wsdl +"'...");

      // Print Import properties to console.
      for(int i =0; i < myImportCollection.Count; ++i)
      {
         Console.WriteLine("Namespace : " + myImportCollection[i].Namespace);
         Console.WriteLine("Location  : " + myImportCollection[i].Location);
         Console.WriteLine("ServiceDescription  : " +
            myImportCollection[i].ServiceDescription.Name);
      }
   }
}
Imports System.Web.Services.Description
Imports System.Collections
Imports System.Xml

Class MySample
   Public Shared Sub Main()
      Console.WriteLine("Import Sample")
      
      Dim myServiceDescription As ServiceDescription = _
         ServiceDescription.Read("StockQuote_vb.wsdl")
      myServiceDescription.Imports.Add( _
         CreateImport("http://localhost/stockquote/schemas", _
         "http://localhost/stockquote/stockquote_vb.xsd"))
      ' Save the ServiceDescripition to an external file.
      myServiceDescription.Write("StockQuote_vb.wsdl")
      Console.WriteLine("Successfully added Import to WSDL document " _
         & "'StockQuote_vb.wsdl'")
      ' Print the import collection to the console.
      PrintImportCollection("StockQuote_vb.wsdl")
        myServiceDescription = _
           ServiceDescription.Read("StockQuoteService_vb.wsdl")
      myServiceDescription.Imports.Insert(0, _
         CreateImport("http://localhost/stockquote/definitions", _
         "http://localhost/stockquote/stockquote_vb.wsdl"))
      ' Save the ServiceDescripition to an external file.
      myServiceDescription.Write("StockQuoteService_vb.wsdl")
      Console.WriteLine("")
      Console.WriteLine("Successfully added Import to " & _
         "WSDL document 'StockQuoteService_vb.wsdl'")
      'Print the import collection to the console.
      PrintImportCollection("StockQuoteService_vb.wsdl")
   End Sub

   ' Creates an Import object with namespace and location.
   Public Shared Function CreateImport(targetNamespace As String, _
      targetlocation As String) As Import
      Dim myImport As New Import()
      myImport.Location = targetlocation
      myImport.Namespace = targetNamespace
      Return myImport
   End Function 'CreateImport

   Public Shared Sub PrintImportCollection(fileName_wsdl As String)

      ' Read import collection properties from generated WSDL file.
      Dim myServiceDescription1 As _
         ServiceDescription = ServiceDescription.Read(fileName_wsdl)
      Dim myImportCollection As ImportCollection = myServiceDescription1.Imports
      Console.WriteLine("Enumerating Import Collection for file '" & _
         fileName_wsdl & "'...")

      ' Print Import properties to the console.
      Dim i As Integer
      For i = 0 To myImportCollection.Count - 1
         Console.WriteLine("Namespace : " & myImportCollection(i).Namespace)
         Console.WriteLine("Location  : " & myImportCollection(i).Location)
         Console.WriteLine("ServiceDescription  : " & _
            myImportCollection(i).ServiceDescription.Name)
      Next i
   End Sub
End Class

備註

元素所 definitions 括住的 Web 服務描述語言 (WSDL) import 元素允許將 XML Web 服務的不同部分區隔成不同的檔,然後視需要匯入。 每個檔的 URL 都與唯一的 XML 標籤前置詞相關聯,代表該檔專案的 XML 命名空間。 如需 WSDL 的詳細資訊,請參閱 WSDL 規格。 如需 XML 命名空間的詳細資訊,請參閱 Namespace 屬性。

建構函式

Import()

初始化 Import 類別的新執行個體。

屬性

Documentation

取得或設定 DocumentableItem 的執行個體的文字文件。

(繼承來源 DocumentableItem)
DocumentationElement

取得或設定 DocumentableItem 的文件項目。

(繼承來源 DocumentableItem)
ExtensibleAttributes

取得或設定型別 XmlAttribute 的陣列,表示符合 Web 服務互通性 (WS-I) Basic Profile 1.1 的 WSDL 屬性擴充。

(繼承來源 DocumentableItem)
Extensions

取得與此 ServiceDescriptionFormatExtensionCollection 類別相關聯的 Import

Extensions

取得與這個 ServiceDescriptionFormatExtensionCollection 關聯的 DocumentableItem

(繼承來源 DocumentableItem)
Location

取得或設定 location 項目的 XML import 屬性 (Attribute) 值。

Namespace

取得或設定 namespace 項目的 XML import 屬性 (Attribute) 值。

Namespaces

取得或設定命名空間前置詞和命名空間的字典,用於在建構 ServiceDescription 物件時保留命名空間前置詞和命名空間。

(繼承來源 DocumentableItem)
ServiceDescription

取得或設定對 ServiceDescription 的參考,Import 為其成員。

方法

Equals(Object)

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

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

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

(繼承來源 Object)

適用於