次の方法で共有


PortTypeCollection.Insert メソッド

指定した 0 から始まるインデックス番号にある PortTypeCollection に、指定した PortType を追加します。

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

パラメータ

  • index
    portType パラメータを挿入する位置の、0 から始まるインデックス番号。
  • portType
    コレクションに追加する PortType

例外

例外の種類 条件
IndexOutOfRangeException index パラメータが 0 未満です。

または

index パラメータが Count より大きい値です。

解説

コレクション内の項目数が既にコレクションの許容量に達している場合は、新しい要素が挿入される前に内部配列が自動的に再割り当てされ、コレクションの容量が 2 倍になります。

index パラメータの値と Count が等しい場合は、指定した PortType インスタンスが PortTypeCollection の末尾に追加されます。

新しい要素を挿入できるように、挿入位置より後にある要素の位置が繰り下がります。

使用例

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

必要条件

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

参照

PortTypeCollection クラス | PortTypeCollection メンバ | System.Web.Services.Description 名前空間