次の方法で共有


Import クラス

XML 名前空間をドキュメントの位置と関連付けます。このクラスは継承できません。

この型のすべてのメンバの一覧については、Import メンバ を参照してください。

System.Object
   System.Web.Services.Description.DocumentableItem
      System.Web.Services.Description.Import

NotInheritable Public Class Import
   Inherits DocumentableItem
[C#]
public sealed class Import : DocumentableItem
[C++]
public __gc __sealed class Import : public DocumentableItem
[JScript]
public class Import extends DocumentableItem

スレッドセーフ

この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。

解説

<definitions> 要素で囲まれた WSDL (Web Services Description Language) <import> 要素を使用すると、XML Web サービスのさまざまな部分を異なるドキュメントに分割して、それらを必要に応じてインポートできます。各ドキュメントの URL は、そのドキュメントの要素の XML 名前空間を表す一意の XML タグ プリフィックスと関連付けられます。WSDL の詳細については、http://www.w3.org/TR/wsdl/ の仕様を参照してください。XML 名前空間の詳細については、 Namespace プロパティのトピックを参照してください。

使用例

[Visual Basic, C#, C++] Import クラスの新しいインスタンスを作成するユーザー定義のメソッドを次の例に示します。

 
Imports System
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("https://localhost/stockquote/schemas", _
         "https://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("https://localhost/stockquote/definitions", _
         "https://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 'Main

   ' 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 'PrintImportCollection
End Class 'MySample

[C#] 
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("https://localhost/stockquote/schemas",
         "https://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("https://localhost/stockquote/definitions",
         "https://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);
      }
   }
}

[C++] 
#using <mscorlib.dll>
#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 = new 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(S"Enumerating Import Collection for file ' {0}'...",
      fileName_wsdl);

   // Print Import properties to console.
   for (int i =0; i < myImportCollection->Count; ++i) 
   {
      Console::WriteLine(S"Namespace : {0}", 
         myImportCollection->Item[i] -> Namespace);
      Console::WriteLine(S"Location  : {0}", 
         myImportCollection->Item[i] -> Location);
      Console::WriteLine(S"ServiceDescription  : {0}", 
         myImportCollection->Item[i]->ServiceDescription->Name);
   }
}

int main()
{
   Console::WriteLine(S"Import Sample");
   ServiceDescription * myServiceDescription = 
      ServiceDescription::Read(S"StockQuote_cpp.wsdl");
   myServiceDescription->Imports->Add(
      CreateImport(S"https://localhost/stockquote/schemas", 
      S"https://localhost/stockquote/stockquote_cpp.xsd"));
   // Save the ServiceDescripition to an external file.
   myServiceDescription->Write(S"StockQuote_cpp.wsdl");
   Console::WriteLine(S"Successfully added Import to WSDL "\
       S"document 'StockQuote_cpp.wsdl'");

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

   //Print the import collection to the console.
   PrintImportCollection(S"StockQuoteService_cpp.wsdl");
}

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

必要条件

名前空間: System.Web.Services.Description

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

アセンブリ: System.Web.Services (System.Web.Services.dll 内)

参照

Import メンバ | System.Web.Services.Description 名前空間