Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

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.

Namespace: System.Web.Services.Description
Assembly: System.Web.Services (in system.web.services.dll)
public sealed class PortTypeCollection : ServiceDescriptionBaseCollection
public final class PortTypeCollection extends ServiceDescriptionBaseCollection
public final class PortTypeCollection extends ServiceDescriptionBaseCollection
Not applicable.
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);
      }
   }
}

import System.*;
import System.Web.Services.Description.*;
import System.Xml.*;
import System.Collections.*;

class MyPortTypeCollectionClass
{
    public static void main(String[] args)
    {
        try {
            // Read the existing Web service description file.
            ServiceDescription myServiceDescription = ServiceDescription.Read(
                "MathService_JSL.wsdl");
            PortTypeCollection myPortTypeCollection = myServiceDescription.
                get_PortTypes();
            int noOfPortTypes = myServiceDescription.get_PortTypes().
                get_Count();
            Console.WriteLine("\nTotal number of PortTypes: " 
                + myServiceDescription.get_PortTypes().get_Count());

            // Get the first PortType in the collection.
            PortType myNewPortType = myPortTypeCollection.get_Item(
                "MathServiceSoap");
            int index = myPortTypeCollection.IndexOf(myNewPortType);
            Console.WriteLine("The PortType with the name " 
                + myNewPortType.get_Name() + " is at index: " + (index + 1));

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

            // Remove the PortType from the collection.
            myPortTypeCollection.Remove(myNewPortType);
            boolean bContains = myPortTypeCollection.Contains(myNewPortType);
            Console.WriteLine("The PortType with the name " 
                + myNewPortType.get_Name() + " exists: " 
                + System.Convert.ToString(bContains));

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

            Console.WriteLine("Adding a PortType: " 
                + myNewPortType.get_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.get_PortTypes().
                get_Count());

            // List the PortTypes available in the WSDL document.
            for (int iCtr = 0; iCtr < myPortTypeCollection.get_Count(); iCtr++) {
                PortType myPortType = myPortTypeCollection.get_Item(iCtr);
                Console.WriteLine("The PortType name is: " 
                    + myPortType.get_Name());
            }
            myServiceDescription.Write("MathService_New.wsdl");
        }
        catch (System.Exception e) {
            Console.WriteLine("Exception: " + e.get_Message());
        }
    } //main
} //MyPortTypeCollectionClass

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 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.