MessagePartCollection.Remove Method
Removes the first occurrence of the specified MessagePart from the MessagePartCollection.
[Visual Basic] Public Sub Remove( _ ByVal messagePart As MessagePart _ ) [C#] public void Remove( MessagePart messagePart ); [C++] public: void Remove( MessagePart* messagePart ); [JScript] public function Remove( messagePart : MessagePart );
Parameters
- messagePart
- The MessagePart to remove from the collection.
Remarks
This method performs a linear search; therefore, the average execution time is proportional to Count.
The elements that follow the removed MessagePart move up to occupy the vacated spot.
Example
[Visual Basic, C#, C++] The following example demonstrates the use of the Remove method.
[Visual Basic] Console.WriteLine("Checking if message is AddHttpPostOut...") Dim myMessage As Message = myServiceDescription.Messages("AddHttpPostOut") If myMessageCollection.Contains(myMessage) Then ' Get the message part collection. Dim myMessagePartCollection As MessagePartCollection = myMessage.Parts ' Get the part named Body. Dim myMessagePart As MessagePart = myMessage.Parts("Body") If myMessagePartCollection.Contains(myMessagePart) Then ' Get the index of the part named Body. Console.WriteLine("Index of Body in MessagePart collection = " & _ myMessagePartCollection.IndexOf(myMessagePart).ToString) Console.WriteLine("Deleting Body from MessagePart Collection...") myMessagePartCollection.Remove(myMessagePart) If myMessagePartCollection.IndexOf(myMessagePart) = -1 Then Console.WriteLine("MessagePart Body successfully deleted " & _ "from the message AddHttpPostOut.") End If End If End If [C#] Console.WriteLine("Checking if message is AddHttpPostOut..."); Message myMessage = myServiceDescription.Messages["AddHttpPostOut"]; if (myMessageCollection.Contains(myMessage)) { // Get the message part collection. MessagePartCollection myMessagePartCollection = myMessage.Parts; // Get the part named Body. MessagePart myMessagePart = myMessage.Parts["Body"]; if (myMessagePartCollection.Contains(myMessagePart)) { // Get the index of the part named Body. Console.WriteLine("Index of Body in MessagePart collection = " + myMessagePartCollection.IndexOf(myMessagePart)); Console.WriteLine("Deleting Body from MessagePart collection..."); myMessagePartCollection.Remove(myMessagePart); if(myMessagePartCollection.IndexOf(myMessagePart)== -1) { Console.WriteLine("MessagePart Body successfully deleted " + "from the message AddHttpPostOut."); } } } [C++] Console::WriteLine(S"Checking if message is AddHttpPostOut..."); Message* myMessage = myServiceDescription->Messages->Item[S"AddHttpPostOut"]; if (myMessageCollection->Contains(myMessage)) { // Get the mssage part collection. MessagePartCollection* myMessagePartCollection = myMessage->Parts; // Get the part named Body. MessagePart* myMessagePart = myMessage->Parts->Item[S"Body"]; if (myMessagePartCollection->Contains(myMessagePart)) { // Get the part named Body. Console::WriteLine(S"Index of Body in MessagePart collection = {0}", __box( myMessagePartCollection->IndexOf(myMessagePart))); Console::WriteLine(S"Deleting Body from MessagePart collection..."); myMessagePartCollection->Remove(myMessagePart); if (myMessagePartCollection->IndexOf(myMessagePart)== -1) Console::WriteLine(S"MessagePart Body successfully deleted "\ S"from the message AddHttpPostOut."); } }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
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
MessagePartCollection Class | MessagePartCollection Members | System.Web.Services.Description Namespace