Export (0) Print
Expand All

MimePartCollection Class

Represents a collection of instances of the MimePart class. This class cannot be inherited.

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

System.Object
   System.Collections.CollectionBase
      System.Web.Services.Description.MimePartCollection

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

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.

Remarks

Each MimePart within the collection represents an extensibility element added to a MimeMultipartRelatedBinding, and specifies the MIME type for a corresponding MessagePart.

For more information about specifying protocols for XML Web services, see Building XML Web Services Using ASP.NET. For more information about Web Services Description Language (WSDL), see the specification at http://www.w3.org/TR/wsdl/.

Example

[Visual Basic, C#, C++] The following example demonstrates the use of the properties and methods exposed by the MimePartCollection class.

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

Public Class MyMimePartCollection
   
   Public Shared Sub Main()
      Dim myServiceDescription As ServiceDescription = ServiceDescription.Read _
                                             ("MimePartCollection_1_Input_vb.wsdl")
      Dim myServiceDescriptionCol As New ServiceDescriptionCollection()
      myServiceDescriptionCol.Add(myServiceDescription)
      Dim myXmlQualifiedName As New XmlQualifiedName("MimeServiceHttpPost", "http://tempuri.org/")
      ' Create a 'Binding' object.
      Dim myBinding As Binding = myServiceDescriptionCol.GetBinding(myXmlQualifiedName)
      Dim myOperationBinding As OperationBinding = Nothing
      Dim i As Integer
      For i = 0 To myBinding.Operations.Count - 1
         If myBinding.Operations(i).Name.Equals("AddNumbers") Then
            myOperationBinding = myBinding.Operations(i)
         End If
      Next i
      Dim myOutputBinding As OutputBinding = myOperationBinding.Output
      Dim myMimeMultipartRelatedBinding As MimeMultipartRelatedBinding = Nothing
      Dim myIEnumerator As IEnumerator = myOutputBinding.Extensions.GetEnumerator()
      While myIEnumerator.MoveNext()
         myMimeMultipartRelatedBinding = CType(myIEnumerator.Current, MimeMultipartRelatedBinding)
      End While
      ' Create an instances of 'MimePartCollection'.
      Dim myMimePartCollection As New MimePartCollection()
      myMimePartCollection = myMimeMultipartRelatedBinding.Parts
      
      Console.WriteLine("Total number of mimepart elements initially is: " + _
                                          myMimePartCollection.Count.ToString())
      ' Create an instance of 'MimePart'.
      Dim myMimePart As New MimePart()
      ' Create an instance of 'MimeXmlBinding'.
      Dim myMimeXmlBinding As New MimeXmlBinding()
      myMimeXmlBinding.Part = "body"
      myMimePart.Extensions.Add(myMimeXmlBinding)
      ' Insert a mimepart at first position.
      myMimePartCollection.Insert(0, myMimePart)
      Console.WriteLine("Inserting a mimepart object...")
      If myMimePartCollection.Contains(myMimePart) Then
         Console.WriteLine("'MimePart' is succesffully added at position: " + _
                                             myMimePartCollection.IndexOf(myMimePart).ToString())
         Console.WriteLine("Total number of mimepart elements after inserting is: " + _
                                                myMimePartCollection.Count.ToString())
      End If
      myServiceDescription.Write("MimePartCollection_1_Output_VB.wsdl")
      Console.WriteLine("MimePartCollection_1_Output_VB.wsdl has been generated successfully.")
   End Sub 'Main
End Class 'MyMimePartCollection

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

public class MyMimePartCollection
{
   public static void Main()
   {
      ServiceDescription myServiceDescription = 
         ServiceDescription.Read("MimePartCollection_1_Input_cs.wsdl");
      ServiceDescriptionCollection myServiceDescriptionCol = 
         new ServiceDescriptionCollection();
      myServiceDescriptionCol.Add(myServiceDescription);
      XmlQualifiedName  myXmlQualifiedName = 
         new  XmlQualifiedName("MimeServiceHttpPost","http://tempuri.org/");
      // Create a 'Binding' object.
      Binding myBinding = myServiceDescriptionCol.GetBinding(myXmlQualifiedName);
      OperationBinding myOperationBinding= null;
      for(int i=0; i<myBinding.Operations.Count; i++) 
      {
         if(myBinding.Operations[i].Name.Equals("AddNumbers"))
         {
            myOperationBinding =myBinding.Operations[i];
         }
      }
      OutputBinding myOutputBinding = myOperationBinding.Output;
      MimeMultipartRelatedBinding myMimeMultipartRelatedBinding = null;
      IEnumerator myIEnumerator = myOutputBinding.Extensions.GetEnumerator();
      while(myIEnumerator.MoveNext())
      { 
         myMimeMultipartRelatedBinding=(MimeMultipartRelatedBinding)myIEnumerator.Current;
      }
      // Create an instances of 'MimePartCollection'.
      MimePartCollection myMimePartCollection = new MimePartCollection();
      myMimePartCollection= myMimeMultipartRelatedBinding.Parts;
      
      Console.WriteLine("Total number of mimepart elements initially is: "
                                       +myMimePartCollection.Count);
      // Create an instance of 'MimePart'.
      MimePart myMimePart=new MimePart();
      // Create an instance of 'MimeXmlBinding'.
      MimeXmlBinding myMimeXmlBinding = new MimeXmlBinding();
      myMimeXmlBinding.Part = "body";
      myMimePart.Extensions.Add(myMimeXmlBinding);
      // Insert a mimepart at first position.
      myMimePartCollection.Insert(0,myMimePart);
      Console.WriteLine("Inserting a mimepart object...");
      if(myMimePartCollection.Contains(myMimePart))
      {
         Console.WriteLine("'MimePart' is succesffully added at position: "
                              +myMimePartCollection.IndexOf(myMimePart));
         Console.WriteLine("Total number of mimepart elements after inserting is: "
                              + myMimePartCollection.Count);
      }
       myServiceDescription.Write("MimePartCollection_1_Output_CS.wsdl");
       Console.WriteLine("MimePartCollection_1_Output_CS.wsdl has been generated successfully.");
   }
}

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

int main()
{
   ServiceDescription * myServiceDescription =
      ServiceDescription::Read(S"MimePartCollection_1_Input_cs.wsdl");
   ServiceDescriptionCollection* myServiceDescriptionCol = new ServiceDescriptionCollection();
   myServiceDescriptionCol->Add(myServiceDescription);
   XmlQualifiedName* myXmlQualifiedName = 
      new XmlQualifiedName(S"MimeServiceHttpPost", S"http://tempuri.org/");
   // Create a 'Binding' object.
   Binding * myBinding = myServiceDescriptionCol->GetBinding(myXmlQualifiedName);
   OperationBinding* myOperationBinding = 0;
   for (int i=0; i<myBinding->Operations->Count; i++)
      if (myBinding->Operations->Item[i]->Name->Equals(S"AddNumbers"))
         myOperationBinding =myBinding->Operations->Item[i];
   OutputBinding * myOutputBinding = myOperationBinding->Output;
   MimeMultipartRelatedBinding* myMimeMultipartRelatedBinding = 0;
   IEnumerator* myIEnumerator = myOutputBinding->Extensions->GetEnumerator();
   while(myIEnumerator->MoveNext())
      myMimeMultipartRelatedBinding = dynamic_cast<MimeMultipartRelatedBinding*>(myIEnumerator->Current);

   // Create an instances of 'MimePartCollection'.
   MimePartCollection* myMimePartCollection = new MimePartCollection();
   myMimePartCollection= myMimeMultipartRelatedBinding->Parts;

   Console::WriteLine(S"Total number of mimepart elements initially is: {0}", 
      __box(myMimePartCollection->Count));
   // Create an instance of 'MimePart'.
   MimePart* myMimePart = new MimePart();
   // Create an instance of 'MimeXmlBinding'.
   MimeXmlBinding* myMimeXmlBinding = new MimeXmlBinding();
   myMimeXmlBinding->Part = S"body";
   myMimePart->Extensions->Add(myMimeXmlBinding);
   // Insert a mimepart at first position.
   myMimePartCollection->Insert(0, myMimePart);
   Console::WriteLine(S"Inserting a mimepart object...");
   if (myMimePartCollection->Contains(myMimePart))
   {
      Console::WriteLine(S"'MimePart' is succesffully added at position: {0}", 
         __box(myMimePartCollection->IndexOf(myMimePart)));
      Console::WriteLine(S"Total number of mimepart elements after inserting is: {0}", __box(myMimePartCollection->Count));
   }
   myServiceDescription->Write(S"MimePartCollection_1_Output_cs.wsdl");
   Console::WriteLine(S"MimePartCollection_1_Output_cs.wsdl has been generated successfully.");
}

[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

MimePartCollection Members | System.Web.Services.Description Namespace

Show:
© 2015 Microsoft