This documentation is archived and is not being maintained.

PortTypeCollection.Insert Method

Adds the specified PortType to the PortTypeCollection at the specified zero-based index.

[Visual Basic]
Public Sub Insert( _
   ByVal index As Integer, _
   ByVal portType As PortType _
)
[C#]
public void Insert(
 int index,
 PortType portType
);
[C++]
public: void Insert(
 int index,
 PortType* portType
);
[JScript]
public function Insert(
   index : int,
 portType : PortType
);

Parameters

index
The zero-based index at which to insert the portType parameter.
portType
The PortType to add to the collection.

Exceptions

Exception Type Condition
IndexOutOfRangeException The index parameter is less than zero.

- or -

The index parameter is greater than Count.

Remarks

If the number of items in the collection already equals the collection's capacity, the capacity is doubled by automatically reallocating the internal array before the new element is inserted.

If the value of the index parameter is equal to Count, the specified PortType instance is added to the end of the PortTypeCollection.

The elements after the insertion point move down to accommodate the new element.

Example

[Visual Basic] 
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: " & noOfPortTypes.ToString())

Dim myNewPortType As PortType = myPortTypeCollection("MathServiceSoap")
' Get the index in the collection.
Dim index As Integer = myPortTypeCollection.IndexOf(myNewPortType)
Console.WriteLine("Removing the PortType named " & _
   myNewPortType.Name)

' Remove the PortType from the collection.
myPortTypeCollection.Remove(myNewPortType)
noOfPortTypes = myServiceDescription.PortTypes.Count
Console.WriteLine(ControlChars.Newline & _
   "Total number of PortTypes: " & noOfPortTypes.ToString())

' Check whether the PortType exists in the collection.
Dim bContains As Boolean = myPortTypeCollection.Contains(myNewPortType)
Console.WriteLine("Port Type'" & myNewPortType.Name & _
   "' exists: " & bContains.ToString())

Console.WriteLine("Adding the 'PortType'")
' Insert a new portType at the index location.
myPortTypeCollection.Insert(index, myNewPortType)

[C#] 
ServiceDescription myServiceDescription = 
   ServiceDescription.Read("MathService_CS.wsdl");

PortTypeCollection myPortTypeCollection = 
   myServiceDescription.PortTypes;
int noOfPortTypes = myServiceDescription.PortTypes.Count;
Console.WriteLine("\nTotal number of PortTypes: " + noOfPortTypes);

PortType myNewPortType = myPortTypeCollection["MathServiceSoap"];

// Get the index in the collection.
int index = myPortTypeCollection.IndexOf(myNewPortType);
Console.WriteLine("Removing the PortType named " 
   + myNewPortType.Name);

// Remove the PortType from the collection.
myPortTypeCollection.Remove(myNewPortType);
noOfPortTypes = myServiceDescription.PortTypes.Count;
Console.WriteLine("\nTotal number of PortTypes: " 
   + noOfPortTypes);

// Check whether the PortType exists in the collection.
bool bContains = myPortTypeCollection.Contains(myNewPortType);
Console.WriteLine("Port Type'" + myNewPortType.Name + "' exists: " 
   + bContains );

Console.WriteLine("Adding the PortType");
// Insert a new portType at the index location.
myPortTypeCollection.Insert(index, myNewPortType);

[C++] 
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(noOfPortTypes));

PortType* myNewPortType = myPortTypeCollection->Item[S"MathServiceSoap"];

// Get the index in the collection.
int index = myPortTypeCollection->IndexOf(myNewPortType);
Console::WriteLine(S"Removing the PortType named {0}", myNewPortType->Name);

// Remove the PortType from the collection.
myPortTypeCollection->Remove(myNewPortType);
noOfPortTypes = myServiceDescription->PortTypes->Count;
Console::WriteLine(S"\nTotal number of PortTypes: {0}", __box(noOfPortTypes));

// Check whether the PortType exists in the collection.
bool bContains = myPortTypeCollection->Contains(myNewPortType);
Console::WriteLine(S"Port Type'{0}' exists: {1}", myNewPortType->Name, __box(bContains));

Console::WriteLine(S"Adding the PortType");
// Insert a new portType at the index location.
myPortTypeCollection->Insert(index, myNewPortType);

[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

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

See Also

PortTypeCollection Class | PortTypeCollection Members | System.Web.Services.Description Namespace

Show: