This documentation is archived and is not being maintained.

PortTypeCollection Class

Represents a collection of instances of the PortType class; that is, a collection of sets of operations supported by the XML Web service. This class cannot be inherited.

For a list of all members of this type, see PortTypeCollection Members.

System.Object
   System.Collections.CollectionBase
      System.Web.Services.Description.ServiceDescriptionBaseCollection
         System.Web.Services.Description.PortTypeCollection

[Visual Basic]
NotInheritable Public Class PortTypeCollection
   Inherits ServiceDescriptionBaseCollection
[C#]
public sealed class PortTypeCollection :
   ServiceDescriptionBaseCollection
[C++]
public __gc __sealed class PortTypeCollection : public
   ServiceDescriptionBaseCollection
[JScript]
public class PortTypeCollection extends
   ServiceDescriptionBaseCollection

Thread Safety

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

Example

[Visual Basic] 
Imports System
Imports System.Web.Services.Description
Imports System.Xml
Imports System.Collections
Imports Microsoft.VisualBasic

Class MyPortTypeCollectionClass
   Public Shared Sub Main()
      Try
         ' Read the existing Web service description file.
         Dim myServiceDescription As ServiceDescription = _
            ServiceDescription.Read("MathService_vb.wsdl")
         Dim myPortTypeCollection As PortTypeCollection = _
            myServiceDescription.PortTypes
         Dim noOfPortTypes As Integer = _
            myServiceDescription.PortTypes.Count
         Console.WriteLine( _
            ControlChars.Newline & "Total number of PortTypes: " & _
            myServiceDescription.PortTypes.Count.ToString())

         ' Get the first PortType in the collection.
         Dim myNewPortType As PortType = _
            myPortTypeCollection("MathServiceSoap")
         Dim index As Integer = myPortTypeCollection.IndexOf(myNewPortType)
         Console.WriteLine("The PortType with the name " & _
            myNewPortType.Name & " is at index: " & (index + 1).ToString())

         Console.WriteLine("Removing the PortType: " & myNewPortType.Name)

         ' Remove the PortType from the collection.
         myPortTypeCollection.Remove(myNewPortType)
         Dim bContains As Boolean = _
            myPortTypeCollection.Contains(myNewPortType)
         Console.WriteLine("The PortType with the Name " & _
            myNewPortType.Name & " exists: " & bContains.ToString())

         Console.WriteLine("Total Number of PortTypes after removing: " & _
            myServiceDescription.PortTypes.Count.ToString())

         Console.WriteLine("Adding a PortType: " & myNewPortType.Name)

         ' Add a new portType from the collection.
         myPortTypeCollection.Add(myNewPortType)

         ' Display the number of portTypes after adding a port.
         Console.WriteLine( _
            "Total Number of PortTypes after adding a new port: " & _
            myServiceDescription.PortTypes.Count.ToString())

         ' List the PortTypes available in the WSDL document.
         Dim myPortType As PortType
         For Each myPortType In  myPortTypeCollection
            Console.WriteLine("The PortType name is: " & myPortType.Name)
         Next myPortType
         myServiceDescription.Write("MathService_New.wsdl")
      Catch e As Exception
         Console.WriteLine("Exception: " & e.Message)
      End Try
   End Sub 'Main
End Class 'MyPortTypeCollectionClass

[C#] 
using System;
using System.Web.Services.Description;
using System.Xml;
using System.Collections;

class MyPortTypeCollectionClass
{
   public static void Main()
   {
      try
      {
         // Read the existing Web service description file.
         ServiceDescription myServiceDescription = 
            ServiceDescription.Read("MathService_CS.wsdl");
         PortTypeCollection myPortTypeCollection = 
            myServiceDescription.PortTypes;
         int noOfPortTypes = myServiceDescription.PortTypes.Count;
         Console.WriteLine("\nTotal number of PortTypes: " 
            + myServiceDescription.PortTypes.Count);
         
         // Get the first PortType in the collection.
         PortType myNewPortType = myPortTypeCollection["MathServiceSoap"];
         int index = myPortTypeCollection.IndexOf(myNewPortType);
         Console.WriteLine("The PortType with the name " + myNewPortType.Name 
            + " is at index: " + (index+1));

         Console.WriteLine("Removing the PortType: " + myNewPortType.Name);

         // Remove the PortType from the collection.
         myPortTypeCollection.Remove(myNewPortType);
         bool bContains = myPortTypeCollection.Contains(myNewPortType);
         Console.WriteLine("The PortType with the name " + myNewPortType.Name 
            + " exists: " + bContains);

         Console.WriteLine("Total number of PortTypes after removing: "
            + myServiceDescription.PortTypes.Count);

         Console.WriteLine("Adding a PortType: " + myNewPortType.Name);

         // Add a new portType from the collection.
         myPortTypeCollection.Add(myNewPortType);

         // Display the number of portTypes after adding a port.
         Console.WriteLine("Total number of PortTypes after "
            + "adding a new port: " + myServiceDescription.PortTypes.Count);

         // List the PortTypes available in the WSDL document.
         foreach(PortType myPortType in myPortTypeCollection)
           Console.WriteLine("The PortType name is: " + myPortType.Name);
           
         myServiceDescription.Write("MathService_New.wsdl");
      }
      catch(Exception e)
      {
         Console.WriteLine("Exception: " + e.Message);
      }
   }
}

[C++] 
#using <mscorlib.dll>
#using <System.Xml.dll>
#using <System.Web.Services.dll>
#using <System.dll>
using namespace System;
using namespace System::Web::Services::Description;
using namespace System::Xml;
using namespace System::Collections;

int main()
{
   try
   {
      // Read the existing Web service description file.
      ServiceDescription* myServiceDescription = 
         ServiceDescription::Read(S"MathService_CS.wsdl");
      PortTypeCollection* myPortTypeCollection = 
         myServiceDescription->PortTypes;
      int noOfPortTypes = myServiceDescription->PortTypes->Count;
      Console::WriteLine(S"\nTotal number of PortTypes: {0}",
         __box(myServiceDescription->PortTypes->Count));

      // Get the first PortType in the collection.
      PortType* myNewPortType = myPortTypeCollection->Item[S"MathServiceSoap"];
      int index = myPortTypeCollection->IndexOf(myNewPortType);
      Console::WriteLine(S"The PortType with the name {0} is at index: {1}",
         myNewPortType->Name, __box((index+1)));

      Console::WriteLine(S"Removing the PortType: {0}", myNewPortType->Name);

      // Remove the PortType from the collection.
      myPortTypeCollection->Remove(myNewPortType);
      bool bContains = myPortTypeCollection->Contains(myNewPortType);
      Console::WriteLine(S"The PortType with the name {0} exists: {1}",
         myNewPortType->Name, __box(bContains));

      Console::WriteLine(S"Total number of PortTypes after removing: {0}",
         __box(myServiceDescription->PortTypes->Count));

      Console::WriteLine(S"Adding a PortType: {0}", myNewPortType->Name);

      // Add a new portType from the collection.
      myPortTypeCollection->Add(myNewPortType);

      // Display the number of portTypes after adding a port.
      Console::WriteLine(S"Total number of PortTypes after adding a new port: {0}",
         __box(myServiceDescription->PortTypes->Count));

      // List the PortTypes available in the WSDL document.
      IEnumerator* myEnum = myPortTypeCollection->GetEnumerator();
      while (myEnum->MoveNext())
      {
         PortType* myPortType = __try_cast<PortType*>(myEnum->Current);
         Console::WriteLine(S"The PortType name is: {0}", myPortType->Name);
      }

      myServiceDescription->Write(S"MathService_New.wsdl");
   }
   catch(Exception* e)
   {
      Console::WriteLine(S"Exception: {0}", e->Message);
   }
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Web.Services.Description

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

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

See Also

PortTypeCollection Members | System.Web.Services.Description Namespace

Show: