This documentation is archived and is not being maintained.

Import Class

Associates an XML namespace with a document location. This class cannot be inherited.

Namespace:  System.Web.Services.Description
Assembly:  System.Web.Services (in System.Web.Services.dll)

[XmlFormatExtensionPointAttribute(L"Extensions")]
public ref class Import sealed : public DocumentableItem

The Web Services Description Language (WSDL) import element that is enclosed by the definitions element allows the separation of different parts of the XML Web service into different documents, which can then be imported as required. Each document's URL is associated with a unique XML tag prefix that represents the XML namespace for that document's elements. For more information about WSDL, see the specification at http://www.w3.org/TR/wsdl/. For more information about XML namespaces, see the Namespace property.

The following example shows a user-defined method that creates a new instance of the Import class.

#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 <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"http://localhost/stockquote/schemas", 
      S"http://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"http://localhost/stockquote/definitions", 
      S"http://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");
}

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

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

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

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